Skip to content
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

Highlighted code block with line-numbers shows too much whitespace #1437

Closed
2 of 5 tasks
halirutan opened this issue Jan 2, 2018 · 4 comments
Closed
2 of 5 tasks

Comments

@halirutan
Copy link

  • This is a question about using the theme.
  • This is a feature request.
  • I believe this to be a bug with the theme.
    • I have updated all gems with bundle update.
    • I have tested locally with bundle exec jekyll build.

Environment informations

  • Minimal Mistakes version: 4.5.0
  • Jekyll version: 3.6.2
  • GitHub Pages hosted: no
  • Operating system: Linux

Using rouge as the highlighter, I believe there is a small glitch when rendering code-blocks with line numbers. Here is how it looks, note the significant whitespace

img

The sample was created with

{% highlight wl linenos %}
{% raw %}
Module[{},
  Sqrt[2]
  4
]
{% endraw %}
{% endhighlight %}

and this is what Jekyll and Rouge produce:

<figure class="highlight"><pre><code class="language-wl" data-lang="wl"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1
2
3
4
</pre></td><td class="code"><pre><span class="bp">Module</span><span class="p">[{}</span><span class="o">,</span><span class="w">
  </span><span class="nb">Sqrt</span><span class="p">[</span><span class="m">2</span><span class="p">]</span><span class="w">
  </span><span class="m">4</span><span class="w">
</span><span class="p">]</span></pre></td></tr></tbody></table></code></pre></figure>

I can set the width of the following to a fixed value, but I'm unable to see how this can be solved in a non-hackish way.

.highlight table td.gutter {
    width: 10px;
    padding-right: 1em;
    color: #bdc1c4;
}

Expected behavior

Something like this

img

@mmistakes
Copy link
Owner

Instead of using Jekyll's highlight tag have you tried using GFM triple backticks and enabling line numbers for Kramdowm/Rouge in your _config.yml.

The CSS might be tricky to get sorted as the HTML markup for Jekyll's highlight tag and what Kramdown spits out is different. It's also a bit of a moving target as they've changed it a few times recently.

Adding the following to the kramdown key in your _config.yml will enable line numbering.

kramdown:
  syntax_highlighter_opts:
    block:
      line_numbers: true

Which ends up looking something like this:

image

ref: jekyll/jekyll#4619 (comment)

@halirutan
Copy link
Author

Instead of using Jekyll's highlight tag have you tried using GFM triple backticks

Thanks for the explanation. I noticed as well that Jekyll produces different HTML for different types of code-block fencing. Unfortunately, I generally dislike line-numbers, but every once in a while I need them to refer to a line. Therefore, I don't want to set it globally. Nevertheless, I fixed my branch of mm by specifying the width.

mmistakes added a commit that referenced this issue Jan 3, 2018
Code blocks with short line widths can cause `td.gutter` width to stretch, adding in undesired white space.

Declaring widths on the table's columns fixes #1437

Add `{% highlight linenos %}` examples to test and demo sites.
@mmistakes
Copy link
Owner

I pushed a small update to _sass/minimal-mistakes/syntax.scss that should fix this issue.

During my tests I had code blocks with long line widths, which didn't show the issue. Your example was a good test because it's fairly narrow. As far as I could tell that was causing the .gutter column to stretch to fill in the extra space.

I added some widths using ems just to be more responsive friend vs. pixels.

image

@halirutan
Copy link
Author

That is nice. I missed the calc part but used otherwise the same fix. I'm going to report another issue that caught my eye.

Terry-Bui added a commit to gaurav1780/comp125_s2_2018 that referenced this issue Sep 7, 2018
kkunapuli pushed a commit to kkunapuli/kkunapuli.github.io that referenced this issue May 30, 2019
Code blocks with short line widths can cause `td.gutter` width to stretch, adding in undesired white space.

Declaring widths on the table's columns fixes mmistakes#1437

Add `{% highlight linenos %}` examples to test and demo sites.
sumeetmondal pushed a commit to sumeetmondal/sumeetmondal.github.io that referenced this issue Sep 10, 2019
Code blocks with short line widths can cause `td.gutter` width to stretch, adding in undesired white space.

Declaring widths on the table's columns fixes mmistakes#1437

Add `{% highlight linenos %}` examples to test and demo sites.
jchwenger pushed a commit to jchwenger/jchwenger.github.io that referenced this issue May 5, 2023
Code blocks with short line widths can cause `td.gutter` width to stretch, adding in undesired white space.

Declaring widths on the table's columns fixes mmistakes#1437

Add `{% highlight linenos %}` examples to test and demo sites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants