Created
June 5, 2021 12:35
-
-
Save hecomi/98ae5cad921e58afb30c7c6b59ed4655 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: http://7cc.hatenadiary.jp/entry/hatena-source-line | |
(function(document) { | |
var pres = document.getElementsByTagName('pre'); | |
for (var i = pres.length; i--;) { | |
var elem = makeLineNumber(pres[i]); | |
pres[i].appendChild(elem); | |
} | |
function makeLineNumber(pre) { | |
var ol = document.createElement('ol'), | |
li = document.createElement('li'), | |
df = document.createDocumentFragment(), | |
br = pre.innerHTML.match(/\n/g); | |
if (br) { | |
ol.className = 'preLine'; | |
ol.setAttribute('role', 'presentation'); | |
for (var i = br.length; i--;) { | |
var cloned_li = li.cloneNode(true); | |
df.appendChild(cloned_li); | |
} | |
ol.appendChild(df); | |
} | |
return ol; | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment