Skip to content

Support highlighting multiple YAML blocks #650

@ag-eitilt

Description

@ag-eitilt

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

Activity

alerque

alerque commented on Jan 3, 2024

@alerque
Member

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alerque@ag-eitilt

        Issue actions

          Support highlighting multiple YAML blocks · Issue #650 · preservim/vim-markdown