It causes weird and impossible to understand errors with Markdown files and have no obvious benefits.
Using {% raw %} doesn’t help because it breaks other things.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: unexpected token: =
at Error.exports.TemplateError (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/lib.js:51:19)
at [object Object].Object.extend.fail (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:64:15)
at [object Object].Object.extend.parsePrimary (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:947:18)
at [object Object].Object.extend.parseUnary (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:882:25)
at [object Object].Object.extend.parsePow (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:856:25)
at [object Object].Object.extend.parseMod (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:844:25)
at [object Object].Object.extend.parseFloorDiv (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:832:25)
at [object Object].Object.extend.parseDiv (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:820:25)
at [object Object].Object.extend.parseMul (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:808:25)
at [object Object].Object.extend.parseSub (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:796:25)
at [object Object].Object.extend.parseAdd (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:784:25)
at [object Object].Object.extend.parseCompare (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:751:25)
at [object Object].Object.extend.parseIn (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:720:23)
at [object Object].Object.extend.parseNot (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:716:21)
at [object Object].Object.extend.parseAnd (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:698:25)
at [object Object].Object.extend.parseOr (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:686:25)
at [object Object].Object.extend.parseInlineIf (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:668:25)
at [object Object].Object.extend.parseExpression (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:663:25)
at [object Object].Object.extend.parseNodes (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1158:30)
at [object Object].Object.extend.parseAsRoot (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1177:42)
at Object.module.exports.parse (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1199:18)
at Object.module.exports.compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/compiler.js:1118:48)
at [object Object].Obj.extend._compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:444:35)
at [object Object].Obj.extend.compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:433:18)
at [object Object].<anonymous> (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:378:22)
at Object.exports.withPrettyErrors (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/lib.js:24:16)
at [object Object].Obj.extend.render (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:374:20)
at [object Object].Obj.extend.renderString (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:261:21)
at /Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/extend/tag.js:56:9
at tryCatcher (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:480:31)
at new Promise (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:70:37)
at Tag.render (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/extend/tag.js:55:10)
at Object.tagFilter [as onRenderEnd] (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/hexo/post.js:253:16)
at /Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/hexo/render.js:55:19
at tryCatcher (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:358:17)
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: tag name expected
at Error.exports.TemplateError (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/lib.js:51:19)
at [object Object].Object.extend.fail (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:64:15)
at [object Object].Object.extend.parseStatement (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:510:18)
at [object Object].Object.extend.parseNodes (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1151:30)
at [object Object].Object.extend.parseAsRoot (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1177:42)
at Object.module.exports.parse (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/parser.js:1199:18)
at Object.module.exports.compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/compiler.js:1118:48)
at [object Object].Obj.extend._compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:444:35)
at [object Object].Obj.extend.compile (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:433:18)
at [object Object].<anonymous> (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:378:22)
at Object.exports.withPrettyErrors (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/lib.js:24:16)
at [object Object].Obj.extend.render (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:374:20)
at [object Object].Obj.extend.renderString (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/nunjucks/src/environment.js:261:21)
at /Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/extend/tag.js:56:9
at tryCatcher (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:480:31)
at new Promise (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:70:37)
at Tag.render (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/extend/tag.js:55:10)
at Object.tagFilter [as onRenderEnd] (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/hexo/post.js:253:16)
at /Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/lib/hexo/render.js:55:19
at tryCatcher (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/tema/Dropbox/Projects/_Repos/blog.sapegin.me/node_modules/hexo/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:358:17)
Related issues: #538, #569, #587, #603, #623, #971, #1079, #1109, #1369, #1372, #1404 and many more.
Nunjuks needs to ignore markdown codeblock else it is impossible to add some templating code in a post. Example of python with flask: https://ghostbin.com/paste/32qdz
Resulting in:
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path) [Line 70, Column 39]
Error: Unable to call `config["items"]`, which is undefined or falsey
at Object.exports.prettifyError (/home/shark/Dev/hexo_rawsec/node_modules/nunjucks/src/lib.js:34:15)
at /home/shark/Dev/hexo_rawsec/node_modules/nunjucks/src/environment.js:486:31
at new_cls.root [as rootRenderFunc] (eval at _compile (/home/shark/Dev/hexo_rawsec/node_modules/nunjucks/src/environment.js:565:24), <anonymous>:18:3)
at new_cls.render (/home/shark/Dev/hexo_rawsec/node_modules/nunjucks/src/environment.js:479:15)
at new_cls.renderString (/home/shark/Dev/hexo_rawsec/node_modules/nunjucks/src/environment.js:327:21)
at /home/shark/Dev/hexo_rawsec/node_modules/hexo/lib/extend/tag.js:66:9
at Promise._execute (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/debuggability.js:300:9)
at Promise._resolveFromExecutor (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:79:10)
at Tag.render (/home/shark/Dev/hexo_rawsec/node_modules/hexo/lib/extend/tag.js:64:10)
at Object.tagFilter [as onRenderEnd] (/home/shark/Dev/hexo_rawsec/node_modules/hexo/lib/hexo/post.js:266:16)
at /home/shark/Dev/hexo_rawsec/node_modules/hexo/lib/hexo/render.js:65:19
at tryCatcher (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues [as _onImmediate] (/home/shark/Dev/hexo_rawsec/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
At least it should be possible to write nunjucks:false or tag-plugin:false in Front-matter.
Note that the unknown path doesn't help to tell which file is causing error so grep skills are required.
@leesei said it helps, but I can confirm that {% raw %} (allowed me to render but some python flask {%% extends "layout.html" %%} {%% block body %%} are still not escaped so the render is a mess) and{% codeblock %} (doesn't escape) didn't helped as @sapegin said.
{% and %} are not the only patterns making Nunjucks failing. {{ and }} seems too.
{% include_code [title] [lang:language] path/to/file %} is the only working tag really escaping breaking patterns.
{% codeblock %} and {% raw %} won't work.
I didn't tried but {% jsfiddle shorttag [tabs] [skin] [width] [height] %}or {% gist gist_id [filename] %} they should work the same as {% include_code %} but with remote file instead of local one.
PS : this is a lot of additional work to move all markdown code block in back-ticks to a separate file and include this. Plus, instead of having a 100% pure markdown file + front matter (easily removable) you get a mix between markdown and hexo tag plugin tags so your file is no more easily exportable or usable for another tool.
Currently, only the renderer could specify if Nunjucks enable or not. https://github.com/hexojs/hexo/pull/2593
I can't use that, this is all enabled or all disabled.
@noraj1337 Another work around is using the HTML encoding, like %7B%7B for {{
@NoahDragon Can't use that neither because %7B%7B in markdown back stick will exactly render %7B%7B and not {{.
PS : %7B is hex encoding and { is HTML entity encoding.
This is very confusing behaviour; it would be nice if nunjucks could be outright disabled for markdown files.
Another example case that fails:
# Some Heading {#custom-id}
Some text...
# Another Heading {#another-id}
Some more text... also, see [here](#custom-id).
It would make more sense to me; if nunjucks processing was desirable on a file then it would just have a filename like my-page.md.nunjucks so that the following operation occurs:
my-page.md.nunjucks gets processed using nunjucks with target of ".md".my-page.md (nunjucks output) gets processed using markdown with target of ".html" since ".html" is the default output of a markdown processor.my-page.html gets processed using html with target remaining ".html" because it is the final target. Html processor doesn't have to do anything at all except return the final result.The default output of nunjucks would probably be ".html" to make that the default output of nunjucks unless something else is specified. For example, a template file with the name "my-page.nunjucks" would be processed with nunjucks processor resulting in a "my-page.html" whilst a "my-page.json.nunjucks" would be processed with nunjucks processor resulting in a "my-page.json".
The advantage with this approach is that use of template engine is explicitly defined on the files that were designed to actually use them. And vanilla .md files remain valid markdown and renderable anywhere.
@kruncher For me it make more sense to configure it in front matters as it is for all parameters that have to be per file config.
If the source of your website is under a DVCS (example: git), a modification of front matters (nunjucks processing to nunjucks disable for example) will be tracked. If using a file extension .nunjucks you will have to rename the file! Plus you will break all file extension recognition for color syntax (ex: in vim, atom, on github or gitlab, etc...).
For me this is a very bad idea.
If you want to put nunjucks syntax in a markdown file.. then it's no longer a markdown file. So it's a huge mistake to confuse the format in my opinion.
If using a file extension .nunjucks you will have to rename the file!
In my opinion not; since it should never have been a markdown file if it contains nunjucks syntax.
{% and %} are not the only patterns making Nunjucks failing. {{ and }} seems too.
And {# #}, amongst others. 😭
Most helpful comment
If you want to put nunjucks syntax in a markdown file.. then it's no longer a markdown file. So it's a huge mistake to confuse the format in my opinion.
In my opinion not; since it should never have been a markdown file if it contains nunjucks syntax.