marp-team / marp-cli

A CLI interface for Marp and Marpit based converters
MIT License
1.9k stars 108 forks source link

Cannot read property 'type' of undefined #300

Closed jtppragg closed 3 years ago

jtppragg commented 3 years ago

I am trying to use markdown-it-footnote from marp-cli but I always get the following error message:

Cannot read property 'type' of undefined

Here there is my engine.js code:

const { Marp } = require('@marp-team/marp-core')

module.exports = (opts) => new Marp(opts)
        .use(require('markdown-it-container'), 'columns')
        .use(require('markdown-it-footnote'))
        .use(require('markdown-it-mark'))

I use several markdown-it plugins, but the error only appears when enabling markdown-it-footnote. However this plugin has online demo working as expected, so I guess the error could be related to marp ...

Thanks!

yhatt commented 3 years ago

I've tried to use same plugins with exactly same engine.js but I cannot reproduce that. At least there are no problem in both of the latest markdown-it-footnote and Marp CLI. Please share procedure to reproduce.

However, some markdown-it plugins may not work as you expected because the most of these plugins are not designed for Marp. markdown-it-footnote is the most mentioned plugin as not working as user expected (https://github.com/marp-team/marp-cli/issues/226). Even if it's worked by fixing that error, footnotes would not render as you expected. (https://github.com/markdown-it/markdown-it-footnote/issues/38)

We always recommend to develop Marp (Marpit) specific plugin like marp(it)-footnote. (https://marpit-api.marp.app/)

jtppragg commented 3 years ago

Thank you for pointing me out the known compatibility problems between this plugin and marp. Anyway I would like to give it a chance. My error happens only when using footnotes in the markdown, for instance using the example code provided with the documentation:

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

    Subsequent paragraphs are indented to show that they
belong to the previous footnote.

If I leave the plugin in engine.js but don't use footnotes in the markdown there is no error message.

Thanks!

jtppragg commented 3 years ago

Just in case this is useful for anyone, I have achieved the desired behavior following @yhatt's suggestion here https://github.com/marp-team/marp-cli/issues/226#issuecomment-622946407 using markdown-it-container as a footnote block and defining this style:

section .note {
  position: absolute;
  left: 70px;
  right: 70px;
  bottom: 50px;
  border-top: 1px solid lightgray;
  padding-top: 5px;
  font-size: 0.5em;
  text-align: left;
}
yhatt commented 3 years ago

Still cannot reproduce. I've tried following the procedure in below but I have no errors.

npm i @marp-team/marp-cli @marp-team/marp-core markdown-it-container markdown-it-footnote markdown-it-mark
npx marp --engine ./engine.js slide.md

engine.js

const { Marp } = require('@marp-team/marp-core')

module.exports = (opts) =>
  new Marp(opts)
    .use(require('markdown-it-container'), 'columns')
    .use(require('markdown-it-footnote'))
    .use(require('markdown-it-mark'))

slide.md

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

    Subsequent paragraphs are indented to show that they
belong to the previous footnote.
jtppragg commented 3 years ago

Try with this slide.md instead, I guess the problem is related to enabling a footer:

---
footer: the footer
---

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

    Subsequent paragraphs are indented to show that they
belong to the previous footnote.

In any case the footnotes appear in the last slide instead of the current slide as desired, so I will continue with this workaround instead: https://github.com/marp-team/marp-cli/issues/300#issuecomment-727890849

Thank you!

yhatt commented 3 years ago

OK. This report shows the footnote plugin designed for Marp(it) should be responsible dealing with Marpit footer. It would be helpful information for plugin developer.

Of course, should not expect Marp support for the plugin designed just for markdown-it.