Can a YAML preamble be defined not at the start?

Sometimes, there are things I’d like to put first.

No, CommonMark doesn’t say anything about preambles or frontmatter or Yaml. If your system doesn’t handle it separately, something like the following will be rendered as a horizontal rule followed by a heading:

---
foo: bar
---
Lorem ipsum.
1 Like

My Typesetting Markdown series describes a set of shell scripts and tooling (bash, pandoc, knitr, yamlp, etc.) that isolates YAML content. I take issue with using YAML to control the output. Instead, IMO, YAML (or any structured file format) should be used to define variables that can be replaced throughout the prose. From there, a theme (e.g., CSS or TeX macros) can be applied to change the look and feel of the final document, be it HTML or PDF. KeenWrite, my free and open-source desktop text editor, takes this approach.

In effect: Variables + Markdown → XHTML → TeX → PDF.

Defining a YAML preamble elsewhere, IMO, is an XY problem. What is the real problem to solve?

@DaveJarvis, it’s not: I want to place HTML5 comments before it.

1 Like

I think having Yaml blocks throughout a document could be useful sometimes. I’ve been thinking about adding ‘backmatter’ support to Basildon SSG, which would just mean it’d be possible to put another block at the end (for example, to hold references etc.). But really, extracting all Yaml blocks (and presumably merging them, or else always having to refer to them by positional index or something) would be pretty good.

It’s a bit of a departure from what’s commonly done, but that’s okay.

For me, the problem to solve was that the frontmatter block sometimes gets really long, and people get confused when opening a file for editing.

2 Likes

@samwilson, I’ve had that occur to me! Having it at the end would significantly improve the readability of large documents that are processed with pandoc.

2 Likes