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

HighlightCode#highlight makes too many assumptions #1342

Closed
citizen428 opened this issue Aug 31, 2013 · 0 comments
Closed

HighlightCode#highlight makes too many assumptions #1342

citizen428 opened this issue Aug 31, 2013 · 0 comments

Comments

@citizen428
Copy link

In line 14 of plugins/pygments_code.rb:

str = pygments(str, lang).match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '')

I've seen this fail both with a NoMethodError for match on nil (when the pygments method returns nil although it shouldn't) as well as with a NoMethodError for [] on nil when the match fails.

True, all of this was triggered by not using raw and endraw appropriately, but still I feel that the above code is unsatisfying and could handle the situation better. Throwing exceptions and leaving the user with no clue as to what happened is rather unacceptable IMHO...

I do have workaround code that at least renders an empty highlighting box into the page so the build doesn't fail and I know which snippet caused the problem, but I won't attach it here for now because (a) it's hacky and (b) I don't think it's really the best way to handle this.

I volunteer to implement a solution though once we have agreed here how and if this should be addressed.

PuercoPop pushed a commit to PuercoPop/octorgopress that referenced this issue Mar 16, 2014
I was running into this problem
imathis/octopress#1342 an awful lot, and it
was happening in really wonky scenarios that seemed to be dependent on
the number of code blocks in a file (?!!)

Using these other code block delimeters for blocks without a language
specified seems to skip the syntax highlighting code path
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

1 participant