-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
enhancementNew feature or requestNew feature or request
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
hauntedhost commentedon May 4, 2019
I'd love to use line numbers as well, any word on this? Let me know if I can help in any way.
arielsalminen commentedon Jan 17, 2020
Wondering the same thing. Is there some way to utilize https://prismjs.com/plugins/line-numbers/ currently?
joshbuchea commentedon Oct 7, 2020
I'm working on an eleventy based starter and I was able to get line numbers working with these two steps:
alwaysWrapLineHighlights
in the eleventy syntax highlighting plugin optionsStep 1
Step 2
Screenshot
Your mileage may vary, remove any styles you don't need. Hope this helps someone! ✌️
falldowngoboone commentedon Mar 28, 2021
@joshbuchea, FYI, I'm seeing issues with this approach. I've documented them here: falldowngoboone/falldowngoboone-com#116.
aaronstezycki commentedon May 7, 2021
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).
danilopolani commentedon Jul 15, 2021
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:
<?php
at the beginning is not wrapped insidehighlight-line
and you have to "whitelist" it along withcode .highlight-line:before
, that's fine..token.comment
, the opening tag (/**
) and closing tag (*/
) are not wrapped inside.highlight-line
but the other lines are, generating an undesired result:Adding
.token.comment
tocode .highlight-line:before
does not solve: the style is messed up, but above all the closing tag is not even counted: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
murtuzaalisurti commentedon Aug 15, 2022
the solution of @joshbuchea works for the most part but it's not reliable and stable. There are issues with the plugin in rendering
span
as mentioned by @falldowngoboone.switowski commentedon Aug 29, 2023
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
alwaysWrapLineHighlights
totrue
).I went through different solutions including enabling markdown-it-attrs (which didn't work, because
python {.myclass}
wrapped in a code fence - three backticks - doesn't work andmyclass
is removed by this plugin) and markdown-it-container (where I wanted to wrap the whole<pre><code>
in a div with a custom class, but that also didn't work, as inside<pre><code>
I didn't have a separate class for each line of code because I didn't enable thealwaysWrapLineHighlights
option).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:
Renders like this:
