I am in the process of creating a website that features chords and lyrics. However, I want to ensure that the chords cannot be copied due to some formatting issues. The main objective is for users to be able to copy the chord and lyrics together and paste them into MS Word or any text editor while still maintaining the content (text, not html) without affecting its layout, which includes having the chord positioned above the corresponding lyrics.
https://i.sstatic.net/ZNz1b.jpg
var markUpChordLines = function() {
jQuery('.post-content').html(function(i, html) {
return html.replace(/\[(.*?)\]/g, '<span class="chord" data-chord="$1"></span>');
});
jQuery('.chord').each(function () {
jQuery(this.nextSibling).wrapAll('<span class="lyric_content"></span>');
jQuery(this.nextSibling).appendTo(this);
});
};
markUpChordLines();
span.chord {
position : relative;
display : inline-flex;
flex-direction : column;
vertical-align : bottom;
}
span.chord:before {
content : attr(data-chord);
position : relative;
font-style : italic;
font-weight : bold;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="post-content">
<p style="display: none;">G D </p>
<p>Al [G]contrario di [D]te </p>
<p>Io[F] non lo s[A]o</p>
<p>[D] Se è g[G]iusto co[F]sì </p>
<p>C[A]omunqu[G]e [D]sia</p>
<p>Io [G#sus]non mi mu[Fm]ovo</p>
<p>Io r[Bm]esto qu[E]i</p>
</div>