Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support highlighting multiple YAML blocks #650

Open
ag-eitilt opened this issue Dec 31, 2023 · 1 comment
Open

Support highlighting multiple YAML blocks #650

ag-eitilt opened this issue Dec 31, 2023 · 1 comment

Comments

@ag-eitilt
Copy link

It's definitely not a commonly-used feature,1 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:

  • If the --- are the entire first line of the document
  • or are preceded by a blank line (to separate it from a setext heading) and are followed by a non-blank line (to separate it from a horizontal rule)2
  • then highlight as YAML until the closing --- or ...; otherwise highlight only the dashes as a horizontal rule.

Footnotes

  1. 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.

  2. 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
Copy link
Member

alerque commented Jan 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants