Skip to content

Conversation

SukkaW
Copy link
Member

@SukkaW SukkaW commented Dec 25, 2019

This PR makes the code blocks result consistent by removing marked.setOptions.highlight.

More info can be found here: hexojs/hexo#4010 (comment)

config.highlight.enable: true

By default hljs is disabled and wrap is enabled. Hexo will render something likes:

<figure class="highlight sh">
  <table>
    ...
  </table>
</figure>

config.highlight.enable: false with hexo-renderer-marked

Since highlight has been disabled, the before_post_render filter will do nothing and leave everything to helpers (powered by nunjucks) and marked (from hexo-renderer-marked).

code() helper is designed to leave everything it should be without applying any highlight.js specific options, so it will render something like:

<pre>
  <code>
    ...
  </code>
</pre>

But for code block wrapped in backticks, it will be rendered by hexo-rendered-marked. And hexo-renderer-marked will call hexo-util.highlight with only str and lang option is given. So it will be rendered to:

<pre>
  <code class="bash">
    ...
  </code>
</pre>

config.highlight.enable: false with hexo-rendered-markdown-it

For code() helper, the result is pretty much the same as with hexo-renderer-marked (just as I said, helpers will not be processed by markdown renderer).

For code block wrapped in backticks, since markdown-it itself has no marked.setOptions.highlight like marked, so the result is the same:

<pre>
  <code>
    ...
  </code>
</pre>

@coveralls
Copy link

coveralls commented Dec 25, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 2029738 on SukkaW:master into 7c7f513 on hexojs:master.

@curbengh
Copy link
Contributor

curbengh commented Dec 26, 2019

To clarify, this PR is necessary to support hexojs/hexo-util#168? so that this plugin is neutral to the choice of syntax highlighting libraries?

@SukkaW
Copy link
Member Author

SukkaW commented Dec 26, 2019

@curbengh

This PR make sure that outputs are the same when config.highlight.enable is false.

hexo-renderer-markdown-it has no built-in syntax either.

@SukkaW SukkaW requested a review from a team December 28, 2019 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants