Module

marksy/frontmatter

src/marksy/frontmatter.pooka

Open the envelope before reading the letter. Only a --- line at the very start opens TOML front matter; a rule later in the document belongs to Markdown. The body keeps its original bytes and its source address.

Pooka
let assert Ok(page) = frontmatter.read("---\ntitle = \"Owl\"\n---\n# Hello\n")
assert page.body == "# Hello\n"
assert page.body_line == 4

API reference

class

Page

src/marksy/frontmatter.pooka:20
class Page(
  metadata: Option(tome.Toml),
  body: String,
  body_line: Int,
  body_byte_offset: Int
)

The body has not been parsed or normalised. Its byte offset starts at zero, while its line number starts at one, just like an editor's gutter.

field

metadata

src/marksy/frontmatter.pooka:21
metadata: Option(tome.Toml)
INFERREDOption($package/tome/tome.Toml)
field

body

src/marksy/frontmatter.pooka:22
body: String
INFERREDString
field

body_line

src/marksy/frontmatter.pooka:23
body_line: Int
INFERREDInt
field

body_byte_offset

src/marksy/frontmatter.pooka:24
body_byte_offset: Int
INFERREDInt
constructor

new

src/marksy/frontmatter.pooka:21
INFERREDfn(Option($package/tome/tome.Toml), String, Int, Int) -> marksy/frontmatter.Page
class

FrontmatterError

src/marksy/frontmatter.pooka:28
class FrontmatterError(line: Int, message: String)

Error lines refer to the complete input, including the opening delimiter.

field

line

src/marksy/frontmatter.pooka:28
line: Int
INFERREDInt
field

message

src/marksy/frontmatter.pooka:28
message: String
INFERREDString
constructor

new

src/marksy/frontmatter.pooka:28
INFERREDfn(Int, String) -> marksy/frontmatter.FrontmatterError
function

read

src/marksy/frontmatter.pooka:37
read(source: String) -> Result(Page, FrontmatterError)

Read optional TOML between exact --- lines. An opening delimiter commits to front matter: missing closing delimiters and invalid TOML are errors.

Pooka
let assert Ok(page) = frontmatter.read("# A page without an envelope\n")
assert page.metadata == None