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

Cannot render headings with ids? #40

Closed
pujiaxun opened this issue Aug 12, 2016 · 10 comments
Closed

Cannot render headings with ids? #40

pujiaxun opened this issue Aug 12, 2016 · 10 comments

Comments

@pujiaxun
Copy link

pujiaxun commented Aug 12, 2016

This renderer cannot generate ids in headings because of Markdown-it plugin not implement it.
So I tried a solution
Just use a plugin markdown-it-named-headings

npm install markdown-it-named-headings --save

And then add one line to render it with this plugin.

parser.use(require('markdown-it-named-headings'))

Just like this.

'use strict';

module.exports = function (data, options) {
  var MdIt = require('markdown-it');
  var cfg = this.config.markdown;
  var opt = (cfg) ? cfg : 'default';
  var parser = (opt === 'default' || opt === 'commonmark' || opt === 'zero') ?
    new MdIt(opt) :
    new MdIt(opt.render);

  parser.use(require('markdown-it-named-headings'))

 if (opt.plugins) {
    parser = opt.plugins.reduce(function (parser, pugs) {
      return parser.use(require(pugs));
    }, parser);
  }

  if (opt.anchors) {
    parser = parser.use(require('./anchors'), opt.anchors);
  }

  return parser.render(data.text);
};

Could I make a PR for this?

@khiav223577
Copy link

Thanks. It works!

@onlyfly34
Copy link

onlyfly34 commented Sep 30, 2017

Is this merged into the project? I had the same issues and this works for me to add
parser.use(require('markdown-it-named-headings'))

@HanchengZhao
Copy link

Hi, I wonder what else do you need to do after adding this line? I still have the problem after doing that. Thanks

@pujiaxun
Copy link
Author

pujiaxun commented Dec 13, 2017 via email

@pujiaxun
Copy link
Author

@HanchengZhao Maybe you can reference this issue. If it doesn't work, I cannot solve it neither.

pujiaxun/pujiaxun.github.io#1

@HanchengZhao
Copy link

@pujiaxun Thanks for the comment. My issue actually has something to do with 'hexo-toc' package. For those who might have the same problem, check out YenYuHsuan/hexo-theme-beantech#11

@noraj
Copy link

noraj commented May 10, 2018

hexo-renderer-markdown-it is not compatible with hexo-toc yet even if hexo-toc claims it.

See bubkoo/hexo-toc#20

@noraj
Copy link

noraj commented May 10, 2018

Is this issue still up to date or it can be closed ?

@pujiaxun
Copy link
Author

@noraj So you mean it's not a bug but a kind of feature or nonsupport? Feel free to close it if you want.

@noraj
Copy link

noraj commented May 13, 2018

@pujiaxun hexo-renderer-markdown-it works perfectly, it's hexo-toc that is a mess.

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

No branches or pull requests

5 participants