arve0 / markdown-it-attrs

Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes
MIT License
300 stars 58 forks source link

crash when a list item containing only a link has an attribute set at its front #128

Closed grant-g closed 2 years ago

grant-g commented 3 years ago

I realize that putting a list item's attribute at its front is not spec'd as being supported, so perhaps this is low priority. Am just passing this along since crashes are never good.)

Markdown-it versions:

% npm ls | grep markdown-it ├─┬ markdown-it@12.0.6 └── markdown-it-attrs@4.0.0

Snippet to run:

var md = require('markdown-it')();
var markdownItAttrs = require('markdown-it-attrs');
md.use(markdownItAttrs, {});
md.render('- {#hi} [link1](./link1)');

Resulting dump:

TypeError: Cannot read property 'type' of undefined
    at Object.exports.getMatchingOpeningToken (/Users/grant/git/marked-it-cli/node_modules/markdown-it-attrs/utils.js:269:17)
    at Object.transform (/Users/grant/git/marked-it-cli/node_modules/markdown-it-attrs/patterns.js:170:34)
    at Array.curlyAttrs (/Users/grant/git/marked-it-cli/node_modules/markdown-it-attrs/index.js:33:19)
    at Core.process (/Users/grant/git/marked-it-cli/node_modules/markdown-it/lib/parser_core.js:51:13)
    at MarkdownIt.parse (/Users/grant/git/marked-it-cli/node_modules/markdown-it/lib/index.js:524:13)
    at MarkdownIt.render (/Users/grant/git/marked-it-cli/node_modules/markdown-it/lib/index.js:544:36)
    at Object.<anonymous> (/Users/grant/git/marked-it-cli/test.js:4:4)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
arve0 commented 2 years ago

Hi 👋 Thanks for reporting! Has been fixed in v4.1.3.