hexojs / hexo-renderer-markdown-it

Markdown-it is a Markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
MIT License
349 stars 60 forks source link

Support for plugins with functions in config #58

Closed oravecz closed 4 years ago

oravecz commented 5 years ago

I wanted to add the markdown-it-container plugin to my project, but there doesn't seem to be a mechanism in Hexo or this library to support the inclusion of a plugin that has functions as part of its configuration. Only solution I can see is to fork the project and hardcode the plugin config. Is there a better way?

EriKWDev commented 5 years ago

I was trying to follow this Chinese developer (https://maqingbo.github.io/2019/03/12/Hexo%20Markdown%20%E6%8B%93%E5%B1%95/) who seems to have gotten markdown-it-containers to work properly. I could, however, not manage to get it to work.

Markdown-it's custom containers are really powerful and it's somewhat of a dealbreaker if I can't get it running.

maxim-usikov commented 4 years ago

Temporary can use this "hack"

markdown:
  plugins:
    # HACK: use options as string, for creating containers
    #
    # SOURCE: https://github.com/alaxn/hexo-renderer-markdown-it/blob/7d09d25958d3c618b4f049f1995962038d2b829d/lib/renderer.js#L14
    #
    # API: https://github.com/markdown-it/markdown-it-container#api
    - name: markdown-it-container
      options: 'error'
    - name: markdown-it-container
      options: 'warning'
    - name: markdown-it-container
      options: 'info'
    - name: markdown-it-container
      options: 'success'
::: error
*here be dragons*
:::

::: warning
*here be dragons*
:::

::: info
*here be dragons*
:::

::: success
*here be dragons*
:::

will convert to:

<div class="error">
  <p><em>here be dragons</em></p>
</div>

<div class="warning">
  <p><em>here be dragons</em></p>
</div>

<div class="info">
  <p><em>here be dragons</em></p>
</div>

<div class="success">
  <p><em>here be dragons</em></p>
</div>
SukkaW commented 4 years ago

Hexo already has this feature called "Tag Plugins".

maxim-usikov commented 4 years ago

Hexo already has this feature called "Tag Plugins".

thank you, I will watch it