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

Bug in v2.1.0 #9

Closed alinex closed 8 years ago

alinex commented 8 years ago

If I use the new version 2.1.0 I get the error:

TypeError: Object #<Object> has no method 'apply'
at MarkdownIt.use (/home/alex/github/node-report/node_modules/markdown-it/lib/index.js:497:10)

I had a look at what the plugin exports (an object):

{ default: [Function] }

Now I switched back to version 2.0.0 and it works again. The plugin exports a function now:

function (md, options) {
  options = _extends({
    toc: true,
    tocClassName: "markdownIt-TOC",
    tocFirstLevel: 1,
    anchorLink: true,
    anchorLinkSymbol: "#",
    anchorLinkBefore: true,
    anchorClassName: "markdownIt-Anchor",
    resetIds: true,
    indentation: "  " }, options);
...

Maybe there is a small problem here which you hopefully can fix.

tylerlong commented 8 years ago

Yes I can confirm the issue. I had to use(markdownItTocAndAnchor.default)

medfreeman commented 8 years ago

That's an issue coming from the change from Babel 5 to Babel 6 between v2.0.0 and v2.1.0. The previous 'export default' transpilation in Babel 5 was incorrect according to ES6 spec. see :

I'll post a pull request that uses this babel plugin, restoring CommonJS import functionality without using the 'default' property, in the case where the ES6 module has ONLY the default export, which is the case here.

MoOx commented 8 years ago

Maybe documenting this is a better idea instead of adding this plugin.

medfreeman commented 8 years ago

Note that this doesn't cause an ES6 style module import to break, as long as there is only a default export the behavior is correct in both worlds, and if not anymore, the aforementioned plugin wouldn't do anything anymore. Since markdown-it plugins have only a single export, i don't see a problem with this behavior. But if you prefer i can make a pull request updating documentation with node syntax example containing 'default'.

MoOx commented 8 years ago

I would prefer that indeed (an es5/commonjs example).