Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix: Invalid highlight html with rouge and linenos #2607 #3435
Fixes broken HTML being generated when using rouge highlighter with linenos feature enabled.
Caused by a naive regex replace done on rouge output to add
Regex replaces the first
Fixes issue #2067
It is actually an issue with how Jekyll does regex-replace on the output of rouge: rouge output is fine, it is Jekyll that is adding tags with a regex replace operation, and assuming that rouge will generate a single
There is not a clear interface between Jekyll and the highlighters. Pygments and rouge generate HTML, and Jekyll does regex-replace on it to inject a
IMHO the proper solution would be to "negotiate" with Pygments and rouge the structure of the output as an HTML document structure, and either:
If this "negotiation" is not an option, it should be Jekyll responsibility to properly deal with whatever output both pygments and rouge generate, possibly avoiding fragile regex-replaces.
I agree here – any changes we make to the output are our bugs to handle.
As a super hacky but kind of clever way of handling this, StackOverflow suggests:
new_str = old_str.reverse.sub(pattern.reverse, replacement.reverse).reverse
I don't think we'll be going with that, but it was too funny not to share.
referenced this pull request
Feb 10, 2015
We don't seem to be doing anything weird with rouge: https://github.com/jekyll/jekyll/blob/master/lib/jekyll/tags/highlight.rb
It's change a little since 2.5.3: https://github.com/jekyll/jekyll/blob/v2.5.3/lib/jekyll/tags/highlight.rb#L107