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

TypeError: Cannot read property 'type' of undefined #26

Closed X1011 closed 5 years ago

X1011 commented 7 years ago

Hi, I'm trying to use this plugin in X1011/X1011.github.io@cb87cf47ea7cba02a0195b37fb2f4ae870552629, but I get this error:

toc-and-anchor $ pug --obj pug-config.js experience.pug 

/home/dan/drive/programming/X1011.github.io/node_modules/pug-filters/lib/handle-filters.js:54
        throw ex;
        ^

TypeError: Cannot read property 'type' of undefined
    at Array.<anonymous> (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it-toc-and-anchor/dist/index.js:102:36)
    at ParserInline.tokenize (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/parser_inline.js:135:22)
    at ParserInline.parse (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/parser_inline.js:163:8)
    at Array.inline (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/rules_core/inline.js:10:23)
    at Core.process (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/parser_core.js:51:13)
    at MarkdownIt.parse (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/index.js:519:13)
    at MarkdownIt.render (/home/dan/drive/programming/X1011.github.io/node_modules/markdown-it/lib/index.js:539:36)
    at filterWithFallback (/home/dan/drive/programming/X1011.github.io/node_modules/pug-filters/lib/handle-filters.js:46:38)
    at walk.includeDependencies (/home/dan/drive/programming/X1011.github.io/node_modules/pug-filters/lib/handle-filters.js:26:18)
    at walkAST (/home/dan/drive/programming/X1011.github.io/node_modules/pug-walk/index.js:13:26)

The offending line corresponds to this one in your source file, and it seems state.tokens.slice(-1) is empty when this occurs.

The same error occurred when i tried the other 2 toc plugins, markdown-it-toc and markdown-it-table-of-contents.

medfreeman commented 5 years ago

fixed in v4.2.0