preservim / vim-markdown

Markdown Vim Mode
4.69k stars 524 forks source link

Support highlighting multiple YAML blocks #650

Open ag-eitilt opened 10 months ago

ag-eitilt commented 10 months ago

It's definitely not a commonly-used feature,[^2] but when Pandoc's standard YAML-metadata extension is enabled, it actually supports metadata being included further into the document:

---
frontmatter: ping
---

Text

---
middlematter: ping
---

Even more text

Pandoc is probably one of the few tools which does support this interleaving (oddly enough, Github supports it when it's closed with --- but not with ..., even though both are legal for the first block) and the dashes could technically be legally interpreted as a horizontal rule, so it might need to be gated behind second option in addition to g:vim_markdown_frontmatter to support people writing for those other tools who did intend for middlematter: ping to be a second body paragraph after a horizontal rule.

I'm not well-versed in writing Vim syntax (my efforts at editing the existing definition have only resulted in the start-of-file block breaking in one manner or another, and have had no effect on the second block) so I can't offer worked code, but the rules would probably need to be:

[^2]: The only reason I'm wanting to is because I'm trying to include computer-processable data alongside the human-readable Markdown describing it, and would prefer to write both beside each other in the same section rather than having multiple screens of metadata at the start of the file, and then multiple more screens of unrelated text before the place it's finally talked about. [^1]: This limitation isn't mentioned in the Pandoc manual, but is the only reasonable way to determine how to highlight things without a lot of lookahead; and in fact Pandoc is implemented to require that non-blank line itself, that's just not in the documentation. (It also actually requires a non-blank line after the dashes even in the first block of the file, but since we're highlighting Markdown+YAML here and not specifically Pandoc, we should probably keep the current lenient syntax for start-of-file frontmatter in case other implementations aren't as picky there.)

alerque commented 10 months ago

This might be a better fit on vim-pandoc-syntax which specifically targets PFM while this plugin hasn't even really worked out what it does target, but in any case contributions are welcome.