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

Plugin crashes when heading has no content #45

Closed davidvandusen closed 5 years ago

davidvandusen commented 6 years ago

When a heading has no content, the plugin crashes because it is trying to access properties of the child nodes of the heading, which don't exist.

Here is the output from a node session illustrating the issue.

$ node
> const markdownIt = require('markdown-it')
undefined
> const markdownItTocAndAnchor = require('markdown-it-toc-and-anchor').default
undefined
> markdownIt().use(markdownItTocAndAnchor).render('## Real heading\n\n##\n\nEmpty heading above')
TypeError: Cannot read property 'type' of undefined
    at Array.<anonymous> (/node_modules/markdown-it-toc-and-anchor/dist/index.js:55:53)
    at Core.process (/node_modules/markdown-it/lib/parser_core.js:51:13)
    at MarkdownIt.parse (/node_modules/markdown-it/lib/index.js:523:13)
    at MarkdownIt.render (/node_modules/markdown-it/lib/index.js:543:36)

The versions used are:

allejo commented 5 years ago

This was introduced in #34 but still hasn't been fixed, see https://github.com/medfreeman/markdown-it-toc-and-anchor/pull/34#issuecomment-395389127

medfreeman commented 5 years ago

fixed in v4.2.0