Module Djot.Frontmatter

YAML metadata at the start of a text, between two lines of ---:

---
title: A note
tags: [a, b]
---

Frontmatter is not djot. It is read here, before the djot parser, and only where a function is given ~frontmatter:true; the parser then gets the text after it. Such a function raises Invalid_argument when this library was built without the yaml package.

A text starts with frontmatter when all of these hold:

Otherwise the text is djot from its first line, where --- is a thematic break. A blank line between two --- lines is not a mapping, so that is two thematic breaks.

type value = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of value list
  6. | `O of (string * value) list
]

A YAML value, as far as JSON has one. This is the type Yaml.value of the yaml package, so a value can be given to that package's functions as it is.

type t = private {
  1. fields : (string * value) list;
    (*

    The mapping, in source order; empty when there is no line between the delimiters.

    *)
  2. text : string;
    (*

    The lines between the delimiters, as written.

    *)
  3. loc : Textloc.t;
    (*

    From the opening --- to the closing one. Set whether or not the parse records positions; Textloc.none when made by make or of_string.

    *)
}

fields is always what text reads as.

val make : (string * value) list -> t

The frontmatter with these fields. Its text is the YAML the yaml package writes for them, and no line for no field.

  • raises Invalid_argument

    if that YAML does not read back as the fields, or if the library was built without yaml.

val of_string : string -> t option

The frontmatter with this text between its delimiters. A newline is added when the text does not end with one. None when the text is not a YAML mapping, or has a --- line, which would end the frontmatter.

  • raises Invalid_argument

    if the library was built without yaml.