medfreeman / markdown-it-toc-and-anchor

markdown-it plugin to add a toc and anchor links in headings
MIT License
60 stars 35 forks source link

Doesn't work #48

Closed john-cj closed 5 years ago

john-cj commented 5 years ago

For some reason, browserified version doesn't work for me. It gives me an error:

Uncaught TypeError: plugin.apply is not a function
    at MarkdownIt.use (markdown-it.js:1083)
    at init.js:20 <-- this is my init file

Line 1083 from makdown-it.js:

MarkdownIt.prototype.use = function (plugin /*, params, ... */) {
  var args = [ this ].concat(Array.prototype.slice.call(arguments, 1));
  plugin.apply(plugin, args); // <----------- Line 1083
  return this;
};

Line 20 from init.js:

var markdownConverter = window.markdownit({
    html:        true,
    breaks:      true,
    linkify:     true,
    typographer: true, quotes: '«»„“',

    highlight: function (str, lang) {
        var esc = markdownConverter.utils.escapeHtml;
        if (lang && hljs.getLanguage(lang)) {
            try {
                return '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' + hljs.highlight(lang, str, true).value + '</code></pre>';
            } catch (__) {}
        }
        return '<pre class="hljs"><code>' + esc(str) + '</code></pre>';
    }
})
    .use(window.markdownitDeflist)
    .use(window.markdownitMark)
    .use(window.markdownitFootnote)
    .use(window.markdownitTocAndAnchor); // <----------- Line 20

I also tried without "window" - it doesn't change anything:

    .use(markdownitDeflist)
    .use(markdownitMark)
    .use(markdownitFootnote)
    .use(markdownitTocAndAnchor);

Another plugins works fine for me (so, I know how to use Browserify). What's wrong with this one?

I haven't tested it without Browserify, however (because I do not know how). Does it work for someone?

Update

If I change my init.js in this way:

    .use(markdownItTocAndAnchor, {});

It will be another error:

Uncaught ReferenceError: markdownItTocAndAnchor is not defined