I am currently working on customizing the appearance of my <code>/<pre>
tags while ensuring that users can still easily highlight and copy the code.
The method I had in mind (shown below) only applies to the first line and doesn't repeat for subsequent lines.
I believe this could be achieved with JavaScript, but I'm unsure about the most efficient way to do so without excessive processing.
body {
font-family: sans-serif;
}
code, pre {
background: #e5f3ff;
}
code.styled,
pre.styled {
display: block;
padding: 8px;
margin: 8px 0;
overflow-x: auto;
}
code.styled::before,
pre.styled::before {
content: "–";
padding-right: 8px;
}
<p>This is an example of using <code>::before</code> to add content,<br>
and still being able to highlight/copy text without copying prefix.</p>
<pre class="styled">
adb wait-for-device
adb reboot-bootloader
fastboot devices
</pre>
<p>Note: You can copy the code without having to worry about the prefix.</p>
Is there a more effective approach to achieving a similar effect across all lines? I am specifically interested in a vanilla JavaScript solution if feasible.