Module

marksy

src/marksy.pooka

Read Markdown into a typed tree, then choose how it should look in HTML. Metadata is an explicit document operation so a plain Markdown thematic break is never mistaken for an unfinished configuration file.

Pooka
assert marksy.to_html("# Owl\n") == "<h1>Owl</h1>\n"

API reference

class

Page

src/marksy.pooka:20
class Page(metadata: Option(tome.Toml), document: ast.Document)
field

metadata

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

document

src/marksy.pooka:20
document: ast.Document
constructor

new

src/marksy.pooka:20
INFERREDfn(Option($package/tome/tome.Toml), marksy/ast.Document) -> marksy.Page
function

parse

src/marksy.pooka:28
parse(source: String) -> ast.Document
INFERREDfn(String) -> marksy/ast.Document

Parse ordinary Markdown without interpreting front matter.

Pooka
let document = marksy.parse("# Owl\n")
let assert [ast.Heading(1, _, _)] = document.blocks
function

to_html

src/marksy.pooka:37
to_html(source: String) -> String
INFERREDfn(String) -> String

Render using escaped raw HTML and a restricted URL policy.

Pooka
assert marksy.to_html("An *owl*.") == "<p>An <em>owl</em>.</p>\n"
function

read

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

Read optional --- TOML metadata and keep body block addresses relative to the complete original input, not to an imaginary file without its header.

function

parse_with

src/marksy.pooka:58
parse_with(source: String, options: syntax.Options) -> ast.Document

Parse explicitly selected extensions while leaving CommonMark as the default.

Pooka
let document = marksy.parse_with("~~owl~~", syntax.gfm())
function

to_html_with

src/marksy.pooka:67
to_html_with(source: String, options: syntax.Options) -> String
INFERREDfn(String, marksy/syntax.Options) -> String

Render selected syntax with the ordinary safe HTML defaults.

Pooka
assert marksy.to_html_with("~~owl~~", syntax.gfm()) == "<p><del>owl</del></p>\n"
function

read_with

src/marksy.pooka:72
read_with(source: String, options: syntax.Options) -> Result(
  Page,
  frontmatter.FrontmatterError
)

Read front matter and apply the selected extensions to its body.

function

parse_checked

src/marksy.pooka:95
parse_checked(source: String, options: syntax.Options, budget: limits.Budget) -> Result(
  ast.Document,
  limits.LimitError
)

Parse untrusted input with explicit syntax and resource budgets.

Pooka
let result = marksy.parse_checked("# Owl", syntax.commonmark(), limits.defaults())
function

to_html_checked

src/marksy.pooka:103
to_html_checked(
  source: String,
  options: syntax.Options,
  rendering: html.Options,
  budget: limits.Budget
) -> Result(String, limits.LimitError)

Budget both parsing and HTML rendering in the same isolated operation.

class

CheckedReadError

src/marksy.pooka:115
class CheckedReadError

Checked document reads distinguish malformed metadata from exhausted budgets.

class

MetadataError

src/marksy.pooka:117
class MetadataError(error: frontmatter.FrontmatterError) is CheckedReadError
field

error

src/marksy.pooka:117
error: frontmatter.FrontmatterError
constructor

new

src/marksy.pooka:117
class

ResourceError

src/marksy.pooka:119
class ResourceError(error: limits.LimitError) is CheckedReadError
field

error

src/marksy.pooka:119
error: limits.LimitError
constructor

new

src/marksy.pooka:119
function

read_checked

src/marksy.pooka:126
read_checked(source: String, options: syntax.Options, budget: limits.Budget) -> Result(
  Page,
  CheckedReadError
)

Budget metadata and Markdown together, retaining their distinct error shapes.

Pooka
let result = marksy.read_checked("---\ntitle = \"Owl\"\n---\n# Hello", syntax.commonmark(), limits.defaults())