-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
How to show line numbers #10
Comments
I'd love to use line numbers as well, any word on this? Let me know if I can help in any way. |
Wondering the same thing. Is there some way to utilize https://prismjs.com/plugins/line-numbers/ currently? |
I'm working on an eleventy based starter and I was able to get line numbers working with these two steps:
Step 1// .eleventy.js
// ...
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
alwaysWrapLineHighlights: true,
}); Step 2/* styles.css */
pre {
counter-reset: lineNumber;
}
code .highlight-line:before {
-webkit-user-select: none;
border-right: 1px solid #404040;
color: #858585;
content: counter(lineNumber);
counter-increment: lineNumber;
display: inline-block;
font-variant-numeric: tabular-nums;
margin-right: 1.2em;
padding-right: 1.2em;
text-align: right;
width: 2.4em;
} ScreenshotYour mileage may vary, remove any styles you don't need. Hope this helps someone! ✌️ |
@joshbuchea, FYI, I'm seeing issues with this approach. I've documented them here: falldowngoboone/falldowngoboone-com#116. |
Just to add a little extra sugar on top of @joshbuchea contribution for cases when you need horizontal scrolling. (Although this might break when you force line wrapping). code .highlight-line:before {
position: sticky; /*added*/
left: 0; /*added*/
background: var(--code-bg); /*added*/
user-select: none;
border-right: 1px solid hsla(0, 0%, 0%, 0.2);
color: hsla(0, 100%, 100%, 0.6);
content: counter(lineNumber);
counter-increment: lineNumber;
display: inline-block;
font-variant-numeric: tabular-nums;
margin-right: 1.2rem;
text-align: center;
width: 3em;
} |
After a bit of testing this, I can assume it's not a stable solution. For example, in PHP code you will have a lot of troubles:
Adding I saw there's a PR from 2020 to implement line numbers without the messy JS code provided by PrismJS, I hope it can be considered: #24 |
the solution of @joshbuchea works for the most part but it's not reliable and stable. There are issues with the plugin in rendering |
Maybe this will help someone, as I've spend quite a bit of time trying to figure out how to enable showing line numbers only for specific code blocks, not site-wide (so without "step 1" that sets the I went through different solutions including enabling markdown-it-attrs (which didn't work, because Turns out this issue can be fixed with a small hack - suffix the language in the code block with "/" (but don't pass any number, unless you want to highlight some code). This enables highlighting lines and highlighting lines in turn enables the line wrapping. And don't forget to add the CSS from step 2 to make this work. This markdown: |
How can I show line numbers in the syntax highlighting?
The text was updated successfully, but these errors were encountered: