hexojs/hexo-renderer-pandoc

Error handling tag id assignment through pandoc syntax

Closed this issue · 2 comments

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 set pandocRenderer.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 . Find register method of class Renderer 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!
  }
}

The grammar conflict is indeed unexpected, and I appreciate the solution you provided. 👍

try hexo >=7.1.1