Error handling tag id assignment through pandoc syntax
Closed this issue · 2 comments
huangy10 commented
In pandoc we can assign id to a generated html tag by
:::{#id-of-tag}
Content of this block
:::
However, this can not be rendered correctly. Actaully, content after this block is truncated. This is obvious caused by nunjuncks compatibility, where {# #}
is a valid block. To be more specific, in hexo/lib/hexo/post.js
, if disableNunjucks
is not set, then the content of the post will be processed in the following way:
if (disableNunjucks === false) {
data.content = cacheObj.escapeAllSwigTags(data.content);
}
Thus the content after {#
is truncated (It will try to find the coresponded #}
till the end of the post). To address this problem, you need to do two things:
- In
hexo-renderer-pandoc
, make sure you setpandocRenderer.disableNunjucks = true
- Upgrade hexo to 7.0.0. If you still using hexo 6.x.x, you need to fix a bug manually by editting
hexo/lib/extend/renderer.js
. Findregister
method of classRenderer
and make sure it looks like this:
register(name, output, fn, sync) {
if (!name) throw new TypeError('name is required');
if (!output) throw new TypeError('output is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');
name = getExtname(name);
output = getExtname(output);
if (sync) {
this.storeSync[name] = fn;
this.storeSync[name].output = output;
this.store[name] = Promise.method(fn);
} else {
if (fn.length > 2) fn = Promise.promisify(fn);
this.store[name] = fn;
}
this.store[name].output = output;
this.store[name].compile = fn.compile;
this.store[name].disableNunjucks = fn.disableNunjucks; // <--- this is the added line!
}
}
stevenjoezhang commented
The grammar conflict is indeed unexpected, and I appreciate the solution you provided. 👍
uiolee commented
try hexo >=7.1.1