You can wrap each space in your pre
elements in a span
with background, so the spaces become visible, but you could copy the text as usually. Here is a JSFiddle example.
Example script (assuming there are no nested tags in the pre
):
var pres = document.querySelectorAll('pre');
for (var i = 0; i < pres.length; i++) {
pres[i].innerHTML = pres[i].innerHTML.replace(/ /g, '<span> </span>')
}
CSS:
pre > span {
display: inline-block;
background: radial-gradient(circle, #cc0, rgba(192,192,0,0) 2px);
}
Alternatively, you can use a custom font for pre
elements, in which the whitespace characters are replaced with something visible.