markdown-it / markdown-it-footnote

Footnotes plugin for markdown-it markdown parser
https://markdown-it.github.io/
MIT License
210 stars 59 forks source link

Normal Footnotes - Cannot read property 'type' of undefined #41

Closed mashdot closed 3 years ago

mashdot commented 3 years ago

Recently I am unable to use Normal Footnotes with references.

Something[^1] something else

[^1]: blah blah 

This causes as Cannot read property 'type' of undefined error which then points to:

node_modules/markdown-it-footnote/index.js:338:49

Which is:

state.tokens = state.tokens.concat(tokens);
      if (state.tokens[state.tokens.length - 1].type === 'paragraph_close') {
        lastParagraph = state.tokens.pop();
      } else {
        lastParagraph = null;
      }

However, your Inline Footnotes do still work fine and cause no errors.

Something^[blah blah] something else

Any ideas?

rlidwka commented 3 years ago

I'm unable to reproduce this error. Just tried this code snippet and it works fine:

var md = require('markdown-it')()
            .use(require('markdown-it-footnote'));

console.log(md.render(`
Something[^1] something else

[^1]: blah blah
`.trim()));

Please show a minimal example of the code that produces this error.

mashdot commented 3 years ago

Just for future seekers, it appears to be related to Nunjucks template processing in 11ty.

I don't have an answer why yet, but at least I know it is not caused by markdown-it-footnote directly.

puzrin commented 3 years ago

That's usually caused by missed second param of .parse() call.

mashdot commented 3 years ago

Oh? How would I resolve this?

mashdot commented 3 years ago

Discovered more about the issue. I used to use .md files as my layouts, which included nunjucks and this was parsed with 11ty. For some reason this has stopped working. So changed the extension to .njk which forces nunjucks parsing first and I no longer get the above issue.