wcoder / highlightjs-line-numbers.js

Line numbering plugin for Highlight.js
https://wcoder.github.io/highlightjs-line-numbers.js/
MIT License
544 stars 126 forks source link

Trim empty first lines of a code block #91

Open PhalanxHead opened 2 years ago

PhalanxHead commented 2 years ago

Basically, when I use a code snippet like below, that I've likely pasted in from another document:

<pre>
<code>
fn main() {
    println!("Hello World"!);
}
</code>
</pre>

Line 1 (using hljs.initLineNumbersOnLoad();) will always be blank, as it registers the line break after the <code> tag as a new line.

It's easy enough to fix, it's just a little annoying.

Describe the solution you'd like Optionally remove the first line from the code block if it's empty.

Describe alternatives you've considered Technically you can do this:

<pre>
<code>fn main() {
    println!("Hello World"!);
}
</code>
</pre>

But it looks a little gross to me idk.

Not a high priority by any means, but I think it would feel nice :)

wcoder commented 2 years ago

It's the default behavior, more details: https://github.com/jekyll/jekyll-help/issues/191

Whitespace inside <pre> elements is always respected by the browser, and output as-is. A newline is treated the same as any other whitespace character.