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
Enabling line numbers with rouge #4619
Comments
@tp How are you writing your code blocks? This works fine for me: https://jekyll-sandbox.herokuapp.com/parkr/5a049fcd77dc17f0121a |
I wanted to convert them to "normal" Markdown syntax with the change and write them with three ` followed by the language, like on github. |
Yep, I was looking for this too when I was upgrading to Jekyll 3. After deciphering all the plugins that the processing goes through I ended up with this: markdown: kramdown
# !github-pages! mandatory › https://help.github.com/articles/using-jekyll-with-pages/#configuration-settings-you-cannot-change
# Since Jekyll 3 the default highlighter is Rouge (replaced Pygments.rb in v44)
highlighter: rouge
# More › http://kramdown.gettalong.org/quickref.html
# Options › http://kramdown.gettalong.org/options.html
kramdown:
input: GFM
# https://github.com/jekyll/jekyll/pull/4090
syntax_highlighter: rouge
# Rouge Highlighter in Kramdown › http://kramdown.gettalong.org/syntax_highlighter/rouge.html
# span, block element options fall back to global
syntax_highlighter_opts:
# Rouge Options › https://github.com/jneen/rouge#full-options
css_class: 'highlight'
#line_numbers: true # bad idea, spans don't need linenos and would inherit this option
span:
line_numbers: false
block:
line_numbers: true
start_line: 1 The big problem with this is that it's not possible to toggle linenos per-code-block. |
I tried your solution but I'm getting some gravitational effects on the code boxes The boxes can end up either shrinking or stretching. Any solution for that? |
I think that's really up to you how you style your site with CSS. Anything from here on is independent of line numbers. An obvious try would be adding
Which helps if you want some customisations here and there. The same trick should work with |
Maybe I wasn't clear. But this box size warping only happens when adding the line numbers.
I added a
I'm not following you here. My web skills are very very limited so I'm likely missing something here. I tried the following (with 3 backticks):
I'm guessing I need an id. But ids are only generated for headings. Even with the BTW, your site looks pretty damn slick! Best jekyll based I've seen. Thanks for the help! |
The structure of a highlighted block with and without line numbers is totally different (div-pre-code VS table as far as I remember), and your styling should accommodate for that. You don't have to use ID, class and attributes, they're all optional:
Thanks, but careful, http://jekyllrb.com is built with Jekyll (sources) ;) |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Jekyll team are limited, and so we are asking for your help. If you can still reproduce this error on the If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced Thank you for all your contributions. |
I think my #4619 (comment) answers OP's original question. kramdown.syntax_highlighter_opts.block.line_numbers = true is the current location of that setting. @tp what do you think? |
I think you're right, thank you @TWiStErRob 👍 |
I was referred here to force line-numbering on. The config posted earlier failed to build, so I ended up pushing changes line-by-line until it started working. Apparently you can't specify So if anybody else comes here, this is what works today (and note I'm defaulting the language): markdown: kramdown
kramdown:
syntax_highlighter: rouge
syntax_highlighter_opts:
default_lang: csharp
css_class: 'highlight'
span:
line_numbers: false
block:
line_numbers: true |
when i apply @TWiStErRob 's _config.yml, i get all code display in one line, why this happened? |
@Pekary that sounds like your CSS may be styling something it shouldn't? We can't know without looking at the code / live version. |
@TWiStErRob it like this |
@Pekary that's a picture, to get any help you would need to share the generated HTML code + CSS in context (running in a browser) to inspect in developer tools. If you don't have a public version try to inspect use Chrome Developer Tools to see what's making it not break lines. |
For me, that worked:
I found that here: |
|
What version of Jekyll are you using (
jekyll -v
)?=> bundle exec jekyll -v
jekyll 3.1.2
What operating system are you using?
OS X 10.11.3
What did you do?
(Please include the content causing the issue, any relevant configuration settings, and the command you ran)
Here are all the variants I tried in my
_config.yml
:What did you expect to see?
I expected source code to be output with line numbers like it was possible using pygments.
What did you see instead?
No line numbers were attached to the output HTML.
The text was updated successfully, but these errors were encountered: