mdx-js / mdx

Markdown for the component era
https://mdxjs.com
MIT License
17.77k stars 1.14k forks source link

consider using docmatter such that frontmatters can be inside comments #1315

Closed balupton closed 4 years ago

balupton commented 4 years ago

Subject of the feature

docmatter is the frontmatter loader used in docpad which was the first big node.js static site generator back in the day - the reason why docmatter is preferable is that matches any characters that are repeated 3 or more times, and supports multiple parsers

most importantly for the user, this allows syntax highlighting in their editor to not get broken by frontmatters, as they can essentially use whichever fence is the most suitable for the language of their choice, so in markdown, they can use a markdown code block as the frontmatter, with language specification and all

Screen Shot 2020-10-30 at 8 11 19 am

I ended up making my own mdx loader for nextjs which includes docmatter support so it supports mdx files like this, which uses a code block, and even json:

however, as this is all unpaid gratis free-time work, I don't have the resources to keep up with the dev efforts of this package

as such, I think it would be better if docmatter was just adopted here instead to enable these benefits

ChristianMurphy commented 4 years ago

@balupton mdx supports frontmatter through https://github.com/remarkjs/remark-frontmatter which supports customizable frontmatter styles https://github.com/micromark/micromark-extension-frontmatter#options and may already be able to support the syntax you are suggesting.

If you are interested in creating your own remark plugin different from the existing frontmatter you are welcome to, there's a great guide on how to do this https://unifiedjs.com/learn Community plugins are absolutely welcome! I'm not sure this is something that would be a good fit for MDX core.

wooorm commented 4 years ago

MDX does not support frontmatter because we use the import/export features from JavaScript.

MDX does allow frontmatter, through plugins. I believe all you want to do, can already be done like that, without needing any changes in MDX.

The reason for doing frontmatter in a parser plugin instead of beforehand, is that positional information still works. Lots of folks use tools to check/lint their MDX, and MDX@next also emits its own parse errors. The positional info will be garbled if frontmatter is stripped beforehand.

balupton commented 4 years ago

Thanks for that. With that information it seems that I can specify three backticks using configuration options for the .mdx files, which is the minimal needed here to get the syntax highlighting benefits I talked about. Unfortunately, the block to specify the parser, rather than configuration options does not seem currently supported, however that is something I can live without for now. If I do decide to re-open, I'll do it on that repo. Thank you for your help.