CHENXCHEN / hexo-renderer-markdown-it-plus

Markdown-it is a markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
https://chchc.me/hexo-article/2017/07/27/hexo-renderer-markdown-it-plus-plugin-demo/
MIT License
115 stars 22 forks source link

toc and anchor plugin #13

Closed noraj closed 6 years ago

noraj commented 6 years ago

You say you are using markdown-it-toc-and-anchor but in dependencies I see only markdown-it-toc that is not the same plugin.

Which one is used ?

And you said in the README that markdown-it-toc-and-anchor is enabled by default but no TOC are generated by default so does this mean we need to do npm i markdown-it-toc-and-anchor --save before ?

And how to configure it ? Like that ?

markdown_it_plus:
    # ...
    plugins:
        - plugin:
            name: markdown-it-toc-and-anchor
            enable: true # not needed if enabled by default ????
            options:
                toc: true
                tocClassName: 'markdownIt-TOC'
                tocFirstLevel: 1
                tocLastLevel: 6
                tocCallback:
                anchorLink: true
                anchorLinkSymbol: '#'
                anchorLinkSpace: true
                anchorLinkSymbolClassName:
                anchorLinkBefore: true
                anchorClassName: 'markdownIt-Anchor'
                resetIds: true
noraj commented 6 years ago

So I uninstalled hexo-renderer-markdown-it and installed hexo-renderer-markdown-it-plus and I also installed manually markdown-it-toc-and-anchor.

So my package.json is:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.4.4"
  },
  "dependencies": {
    "hexo": "^3.4.4",
    "hexo-deployer-git": "^0.3.1",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-feed": "^1.2.2",
    "hexo-generator-json-content": "^3.0.1",
    "hexo-generator-tag": "^0.2.0",
    "hexo-i18n": "^0.2.1",
    "hexo-pagination": "^0.1.0",
    "hexo-renderer-ejs": "^0.3.1",
    "hexo-renderer-markdown-it-plus": "^1.0.3",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.3.1",
    "hexo-sliding-spoiler": "^1.1.6",
    "hexo-tag-asciinema": "0.0.1",
    "hexo-tag-bootstrap": "^0.1.2",
    "markdown-it-toc-and-anchor": "^4.1.2"
  }
}

And my _config.yml contains:

# Markdown-it-plus config
## https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus
markdown_it_plus:
    html: true
    linkify: true
    plugins:
      - plugin:
        name: markdown-it-toc-and-anchor
        enable: true
        options:
          toc: true
          tocClassName: 'markdownIt-TOC'
          tocFirstLevel: 2
          tocLastLevel: 6
          tocCallback:
          anchorLink: true
          anchorLinkSymbol: '🔗'
          anchorLinkSpace: true
          anchorLinkSymbolClassName:
          anchorLinkBefore: true
          anchorClassName: 'markdownIt-Anchor'
          resetIds: true
      - plugin:
        name: markdown-it-emoji
        enable: false
      - plugin:
        name: markdown-it-sub
        enable: false
      - plugin:
        name: markdown-it-sup
        enable: false
      - plugin:
        name: markdown-it-deflist
        enable: false
      - plugin:
        name: markdown-it-abbr
        enable: false
      - plugin:
        name: markdown-it-footnote
        enable: false
      - plugin:
        name: markdown-it-mark
        enable: false
      - plugin:
        name: '@iktakahiro/markdown-it-katex'
        enable: false

But no toc and anchors are rendered.

noraj commented 6 years ago

Are those other plugins able to work :

CHENXCHEN commented 6 years ago

There is a problem, this plugin's npm package and github repository are different code. If you use the npm package, you will meet this problem TypeError: Cannot read property 'type' of undefined,but it already fix in github repository, i had submit issue for that #36, the author seems to have forgotten his child. I try to npm install from github but failed, so i have to clone the code and place here used here

noraj commented 6 years ago

Ok so how do I make it works ?

CHENXCHEN commented 6 years ago

It works by default..

noraj commented 6 years ago

@CHENXCHEN As you can see in my two first post that didn't work for me, that's why I opened an issue.

CHENXCHEN commented 6 years ago

This demo project may help you.

noraj commented 6 years ago
  1. You need to write in the readme that @[toc] is the required tag to generate the readme.
  2. There is a first and last level for TOC but not for anchors. At least markdown-it take level for the minimum level of ID creation. There should be a AnchorFirstLevel and AnchorLastLevel too. For example I need h2 to h6.
CHENXCHEN commented 6 years ago
  1. Okay, i will update readme
  2. This plugin (markdown-it-toc-and-anchor) do not support for that.
noraj commented 6 years ago
  1. That's why I think hexo-rendered-markdown-it-plus should use the anchor generation from markdown-it like in hexo-rendered-markdown-it and use a dedicated plugin for toc generation, not a plugin doing both at the same time.

This should be achievable with one of the plugin I mentioned before https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus/issues/13#issuecomment-388144623.

I'll consider using hexo-rendered-markdown-it-plus when it will have a proper behavior. Today it makes render my website too ugly.

CHENXCHEN commented 6 years ago

I don't understand what your means.. You can make this plugin disable if you want, and use other third-party plugins instead.

noraj commented 6 years ago

I didn't managed to make an external plugin work with this project.