j-f1/eleventy-hast-jsx

`component` shortcode doesn't work in Markdown `.md` files

svicalifornia opened this issue · 4 comments

Trying to use the component shortcode inside a Markdown file, I get this error:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering njk template ./eleventy/index.md (via TemplateContentRenderError)
[11ty] 2. Cannot read properties of undefined (reading 'eleventy'), file:./eleventy/index.md, line:4, col:1 (via RenderError)
[11ty] 3. Cannot read properties of undefined (reading 'eleventy') (via TypeError)
[11ty] 
[11ty] Original error stack trace: TypeError: Cannot read properties of undefined (reading 'eleventy')
[11ty]     at Object.liquid (.../node_modules/.pnpm/eleventy-hast-jsx@0.3.1/node_modules/eleventy-hast-jsx/src/shortcodes.js:80:48)

Digging into the eleventy-hast-jsx code, I see that the shortcode functions try to access this.ctx.eleventy — however, the ctx property is undefined in a Markdown file.

The JSDoc marks this as being of type ShortcodeThis, defined in types.d.ts. That file has a link to this Eleventy docs page: https://www.11ty.dev/docs/data-eleventy-supplied

However, that docs page doesn't say anything about a ctx property. Is that an undocumented property?

Is there a way to get shortcodes to work in Markdown files?

And presumably it should work in Markdown files just as well as it does in Liquid files, as the Eleventy shortcode docs say:

Markdown files are pre-processed as Liquid templates by default. This means that shortcodes available in Liquid templates are also available in Markdown files. Likewise, if you change the template engine for Markdown files, the shortcodes available for that templating language will also be available in Markdown files.

j-f1 commented

Thanks! The upcoming v2 has official support for this.eleventy which I will soon release an update to migrate over to.

j-f1 commented

I believe this is fixed in v0.3.2, let me know if you’re still having problems!

j-f1 commented

Fixed it even more in v0.3.3!