Module
marksy
src/marksy.pookaRead 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.
assert marksy.to_html("# Owl\n") == "<h1>Owl</h1>\n"
API reference
class Page(metadata: Option(tome.Toml), document: ast.Document)
metadata: Option(tome.Toml)
Option($package/tome/tome.Toml)document: ast.Document
marksy/ast.Document
fn(Option($package/tome/tome.Toml), marksy/ast.Document) -> marksy.Pageparse(source: String) -> ast.Document
fn(String) -> marksy/ast.DocumentParse ordinary Markdown without interpreting front matter.
let document = marksy.parse("# Owl\n")
let assert [ast.Heading(1, _, _)] = document.blocks
to_html(source: String) -> String
fn(String) -> StringRender using escaped raw HTML and a restricted URL policy.
assert marksy.to_html("An *owl*.") == "<p>An <em>owl</em>.</p>\n"
read(source: String) -> Result(Page, frontmatter.FrontmatterError)
fn(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.
parse_with(source: String, options: syntax.Options) -> ast.Document
fn(String, marksy/syntax.Options) -> marksy/ast.DocumentParse explicitly selected extensions while leaving CommonMark as the default.
let document = marksy.parse_with("~~owl~~", syntax.gfm())
to_html_with(source: String, options: syntax.Options) -> String
fn(String, marksy/syntax.Options) -> StringRender selected syntax with the ordinary safe HTML defaults.
assert marksy.to_html_with("~~owl~~", syntax.gfm()) == "<p><del>owl</del></p>\n"
read_with(source: String, options: syntax.Options) -> Result(
Page,
frontmatter.FrontmatterError
)
fn(String, marksy/syntax.Options) -> Result(marksy.Page, marksy/frontmatter.FrontmatterError)Read front matter and apply the selected extensions to its body.
parse_checked(source: String, options: syntax.Options, budget: limits.Budget) -> Result(
ast.Document,
limits.LimitError
)
fn(String, marksy/syntax.Options, marksy/limits.Budget) -> Result(marksy/ast.Document, marksy/limits.LimitError)Parse untrusted input with explicit syntax and resource budgets.
let result = marksy.parse_checked("# Owl", syntax.commonmark(), limits.defaults())
to_html_checked(
source: String,
options: syntax.Options,
rendering: html.Options,
budget: limits.Budget
) -> Result(String, limits.LimitError)
fn(String, marksy/syntax.Options, marksy/html.Options, marksy/limits.Budget) -> Result(String, marksy/limits.LimitError)Budget both parsing and HTML rendering in the same isolated operation.
class CheckedReadError
Checked document reads distinguish malformed metadata from exhausted budgets.
class MetadataError(error: frontmatter.FrontmatterError) is CheckedReadError
error: frontmatter.FrontmatterError
fn(marksy/frontmatter.FrontmatterError) -> marksy.MetadataErrorclass ResourceError(error: limits.LimitError) is CheckedReadError
error: limits.LimitError
marksy/limits.LimitError
fn(marksy/limits.LimitError) -> marksy.ResourceErrorread_checked(source: String, options: syntax.Options, budget: limits.Budget) -> Result(
Page,
CheckedReadError
)
fn(String, marksy/syntax.Options, marksy/limits.Budget) -> Result(marksy.Page, marksy.CheckedReadError)Budget metadata and Markdown together, retaining their distinct error shapes.
let result = marksy.read_checked("---\ntitle = \"Owl\"\n---\n# Hello", syntax.commonmark(), limits.defaults())