Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use valid css class names when pygments language contains invalid chars, eg html+django #994

Merged
merged 2 commits into from

3 participants

@stephenmcd

Pygments has some lexers that combine multiple languages and are referenced by name using the plus sign, eg "html+django" is a valid lexer name.

In the highlight tag, the lexer name also gets used as the CSS class name in the wrapping HTML <code> block, but the plus sign is invalid here.

This change simply converts plus signs to minus signs, to conform with valid CSS class names.

@parkr
Owner

I think we'd want to normalize the lang elsewhere, right? And I'd love tests for this so we don't break it in the future. They're in ./test/test_tags.rb.

@stephenmcd

Is it used as a CSS classname anywhere else? As far as Pygments goes it's doing the right thing, so nothing needs to change there.

As for tests I haven't written Ruby for a couple of years, so I'm a bit out of my depth there. Happy to give it a go but I'd need some guidance.

@mattr-
Owner

@stephenmcd I'd be happy to pair with you remotely on this

@stephenmcd

Thanks @mattr- !

Might not be right away - I've a ton of outstanding work on my own projects unfortunately. But if I get around to it I'll ping you here.

@parkr parkr closed this
@stephenmcd

Did this get fixed?

@parkr parkr reopened this
@parkr
Owner

Nope, it was just closed by accident.

@stephenmcd

Cool!

Would you like to go ahead and merge the fix? I don't do Ruby or anything with Jekyll these days, so I have almost no exposure to the code base - but as I understood, the line changed in this fix is the only location that deals with mapping language names to CSS class names, which the issue specifically is.

Doesn't seem worthwhile to leave a bug opened for this long when the fix is literally as trivial as they get. Just my 2 cents as someone who does way too much open source maintenance :-)

@parkr
Owner

So this fix is pretty trivial but it doesn't take into account @lang being nil, in which case it'll just freak out. Can you call .to_s first, before gsub? Thanks!

@stephenmcd

No sweat, all done - thanks a lot!

@parkr parkr merged commit d80471c into jekyll:master

1 check was pending

Details default The Travis CI build is in progress
@parkr
Owner

Boom! Thanks @stephenmcd :)

@lmullen lmullen referenced this pull request from a commit in lmullen/jekyll
@parkr parkr Update history to reflect merge of #994 [ci skip] d8e36b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2013
  1. @stephenmcd
Commits on Mar 17, 2014
  1. @stephenmcd
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/jekyll/tags/highlight.rb
View
2  lib/jekyll/tags/highlight.rb
@@ -53,7 +53,7 @@ def render_pygments(context, code)
output = add_code_tags(
Pygments.highlight(code, :lexer => @lang, :options => @options),
- @lang
+ @lang.to_s.gsub("+", "-")
)
output = context["pygments_prefix"] + output if context["pygments_prefix"]
Something went wrong with that request. Please try again.