-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add line numbers to code blocks (use existing script) #410
Comments
I'd be happy to accept a pull request for this, if you want to include it in SOX :) |
shu8
changed the title
Merge SO - Code line nums
Add line numbers to code blocks (use existing script)
Jun 26, 2019
Any reason for the removal of that label? @mezmi |
Does this look good? Partly inspired from Stacks. [...document.querySelectorAll('.s-prose pre')].forEach(codeBlock => {
codeBlock.classList.add('s-code-block'); // add the stacks class in case it doesn't already exist
// the last item of the array is just a newline and not an actual line of code
const lineNumber = codeBlock.innerText.split(/\r?\n/).length - 1;
// index is zero-based, so we need to increase by 1
const lineDivs = [...Array(lineNumber).keys()].map(number => `<div>${number + 1}</div>`).join('');
codeBlock.insertAdjacentHTML('afterbegin', `<code class="s-code-block--line-numbers">${lineDivs}</code>`);
}); |
@double-beep that looks perfect! would you mind making a quick PR to add that in as a feature? :) /cc @SmartManoj! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not maintained 5 years old,
https://greasyfork.org/en/scripts/1781-so-code-line-nums
Updated one
https://raw.githubusercontent.com/SmartManoj/SmartUserScripts/master/SO_Lines.user.js
The text was updated successfully, but these errors were encountered: