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

Fenced code block trips up Liquid, because it tries to interpret the text instead of rendering it verbatim #814

Closed
paxan opened this Issue Feb 19, 2013 · 13 comments

Comments

Projects
None yet
5 participants
@paxan

paxan commented Feb 19, 2013

Hi, I've configured my Jekyll site to use redcarpet like so:

...
markdown: redcarpet
redcarpet:
  extensions: []
...

This gist shows a fenced code block that produces the following exception in Jekyll:

Liquid Exception: Tag '{%' was not properly terminated with regexp: /\%\}/  in 2013-02-18-boom.markdown
.../gems/liquid-2.4.1/lib/liquid/block.rb:35:in `parse'
.../gems/liquid-2.4.1/lib/liquid/document.rb:5:in `initialize'
.../gems/liquid-2.4.1/lib/liquid/template.rb:58:in `new'
.../gems/liquid-2.4.1/lib/liquid/template.rb:58:in `parse'
.../gems/liquid-2.4.1/lib/liquid/template.rb:46:in `parse'
.../gems/jekyll-0.12.0/lib/jekyll/convertible.rb:79:in `do_layout'
.../gems/jekyll-0.12.0/lib/jekyll/post.rb:195:in `render'
.../gems/jekyll-0.12.0/lib/jekyll/site.rb:200:in `block in render'
.../gems/jekyll-0.12.0/lib/jekyll/site.rb:199:in `each'
.../gems/jekyll-0.12.0/lib/jekyll/site.rb:199:in `render'
.../gems/jekyll-0.12.0/lib/jekyll/site.rb:41:in `process'

Just for fun, I'm embedding the same code block directly in this issue, and as you see it doesn't kill the GFM renderer used by GitHub.

(defn ^String metadata-path
  [prefix]
  (->> valid-segments
       (s/join ",")
       (format "%s/{%s}/metadata*" prefix)))
@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Feb 19, 2013

Contributor

I just saw the gist link. Can you show the liquid which surrounds the stuff.

Contributor

tombell commented Feb 19, 2013

I just saw the gist link. Can you show the liquid which surrounds the stuff.

@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Feb 19, 2013

Contributor

I mean, can you show us the liquid code for the templates, it sounds like you actually have unclosed liquid tags

Contributor

tombell commented Feb 19, 2013

I mean, can you show us the liquid code for the templates, it sounds like you actually have unclosed liquid tags

@paxan

This comment has been minimized.

Show comment
Hide comment
@paxan

paxan Feb 19, 2013

@tombell I've revised the gist to show the exact jekyll post file.

Raw link: https://gist.github.com/paxan/4982896/raw/9689e23034c0b2210f3a0e64708da69a7ea14bd8/gistfile1.txt

The culprit is the second %s that is surrounded by {} inside format function call.

paxan commented Feb 19, 2013

@tombell I've revised the gist to show the exact jekyll post file.

Raw link: https://gist.github.com/paxan/4982896/raw/9689e23034c0b2210f3a0e64708da69a7ea14bd8/gistfile1.txt

The culprit is the second %s that is surrounded by {} inside format function call.

@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Feb 19, 2013

Contributor

Initial solution is to put {% raw %} {% endraw %} around your fenced code blocks. There isn't much else that can solve this because the {% will be rendered by Liquid, unless you use {% raw %}.

Contributor

tombell commented Feb 19, 2013

Initial solution is to put {% raw %} {% endraw %} around your fenced code blocks. There isn't much else that can solve this because the {% will be rendered by Liquid, unless you use {% raw %}.

@paxan

This comment has been minimized.

Show comment
Hide comment
@paxan

paxan Feb 19, 2013

FYI @tombell, this workaround works well enough. I tested with a locally running jekyll and GitHub Pages jekyll site generator.

paxan commented Feb 19, 2013

FYI @tombell, this workaround works well enough. I tested with a locally running jekyll and GitHub Pages jekyll site generator.

@paxan

This comment has been minimized.

Show comment
Hide comment
@paxan

paxan Feb 19, 2013

@mojombo it would be interesting to know what GitHub does to protect GFM rendering from this bug elsewhere? Clearly nothing needs to be done to use triple backticks in issues, pull requests, &c. Probably that GFM renderer has nothing to do with Jekyll's.

paxan commented Feb 19, 2013

@mojombo it would be interesting to know what GitHub does to protect GFM rendering from this bug elsewhere? Clearly nothing needs to be done to use triple backticks in issues, pull requests, &c. Probably that GFM renderer has nothing to do with Jekyll's.

@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Feb 19, 2013

Contributor

GFM doesn't use Liquid.

Contributor

tombell commented Feb 19, 2013

GFM doesn't use Liquid.

@paxan

This comment has been minimized.

Show comment
Hide comment
@paxan

paxan Feb 19, 2013

OK, the following is a terrible hack because it wraps everything that looks like fenced code example in "raw-endraw" enclosure regardless of what rendering engine is used: it just assumes it works with redcarpet-like fences.

https://github.com/paxan/jekyll/compare/fenced-code-examples-mustnt-crash-jekyll

I welcome suggestions on making it more robust and less terrible. It also needs tests 😁 before being seriously considered.

paxan commented Feb 19, 2013

OK, the following is a terrible hack because it wraps everything that looks like fenced code example in "raw-endraw" enclosure regardless of what rendering engine is used: it just assumes it works with redcarpet-like fences.

https://github.com/paxan/jekyll/compare/fenced-code-examples-mustnt-crash-jekyll

I welcome suggestions on making it more robust and less terrible. It also needs tests 😁 before being seriously considered.

@enure

This comment has been minimized.

Show comment
Hide comment
@enure

enure Feb 22, 2013

For what it's worth, this same issue occurs when you try to include and use Mustache.js or other js templating libraries that use {{ and }} for start/end tags.

I solved it by using {% raw %} and {% endraw %}, as mentioned above.

enure commented Feb 22, 2013

For what it's worth, this same issue occurs when you try to include and use Mustache.js or other js templating libraries that use {{ and }} for start/end tags.

I solved it by using {% raw %} and {% endraw %}, as mentioned above.

@paxan

This comment has been minimized.

Show comment
Hide comment
@paxan

paxan Feb 23, 2013

So if you have "fenced" area of text, doesn't it imply by the use of term fence, that inside of it I may use whatever combination of curly and/or hairy braces I like? Say I am authoring a tutorial about using Mustache using GFM-style Markdown (which, BTW, doesn't say anything about having to protect fences with raw/endraw), how would I give any examples of using {{ foo }} if fences didn't work?

paxan commented Feb 23, 2013

So if you have "fenced" area of text, doesn't it imply by the use of term fence, that inside of it I may use whatever combination of curly and/or hairy braces I like? Say I am authoring a tutorial about using Mustache using GFM-style Markdown (which, BTW, doesn't say anything about having to protect fences with raw/endraw), how would I give any examples of using {{ foo }} if fences didn't work?

@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Feb 24, 2013

Contributor

Could people please realise that GFM used on GitHub doesn't have Liquid as an intermediate template language, Jekyll uses Liquid AND a textile/markdown engine.

Contributor

tombell commented Feb 24, 2013

Could people please realise that GFM used on GitHub doesn't have Liquid as an intermediate template language, Jekyll uses Liquid AND a textile/markdown engine.

@tombell

This comment has been minimized.

Show comment
Hide comment
@tombell

tombell Mar 20, 2013

Contributor

This issue isn't a bug, it's a caveat of using a templating language with markdown. You can close this @parkr

Contributor

tombell commented Mar 20, 2013

This issue isn't a bug, it's a caveat of using a templating language with markdown. You can close this @parkr

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Mar 20, 2013

Member

Good catch man! Thanks!

Member

parkr commented Mar 20, 2013

Good catch man! Thanks!

@parkr parkr closed this Mar 20, 2013

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.