function wrapTextLinesInSpan(element){ const lines = element.textContent.split('\n').filter(Boolean); element.textContent = ''; for (let index = 0; index < lines.length; index++) { const span = document.createElement('span'); span.className = 'line'; span.textContent = lines[index]; element.appendChild(span); if(index < lines.length - 1){ element.appendChild(document.createTextNode('\n')); } } } document.querySelectorAll('pre.number-lines').forEach(wrapTextLinesInSpan);