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

Error handling tag id assignment through pandoc syntax #60

Closed
huangy10 opened this issue Sep 23, 2023 · 2 comments · Fixed by hexojs/hexo#5395
Closed

Error handling tag id assignment through pandoc syntax #60

huangy10 opened this issue Sep 23, 2023 · 2 comments · Fixed by hexojs/hexo#5395

Comments

@huangy10
Copy link

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!
  }
}
@stevenjoezhang
Copy link
Member

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

@uiolee
Copy link
Member

uiolee commented Apr 18, 2024

try hexo >=7.1.1

@uiolee uiolee closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants