Expand description
tabnas-markdown: a CommonMark 0.31.2 parser with the GFM extensions
(tables, strikethrough, task list items, autolink literals and the
disallowed-raw-HTML filter), built as a plugin on the bare tabnas
engine.
let doc = tabnas_markdown::parse("# Hello *world*")?;
assert_eq!(doc.to_json()["children"][0]["type"], "heading");This file is only the plugin wiring and the public surface. The parser
itself is engine-free and lives in commonmark and the modules it
pulls in (block, inline, html, common, node), so it
can be exercised, and the conformance suite run, without the engine.
Nothing under commonmark.rs may import it.
The parse result is a native CommonMark node tree (Tree); ast
projects it to the map-based JSON AST this package has always returned
(as a tabnas::Value), and html renders it for to_html.
Nesting is bounded, at MAX_CONTAINER_NESTING container blocks and
MAX_INLINE_NESTING inline containers, which the canonical
TypeScript does not do: a Value is dropped and converted
recursively, so an unbounded AST could overflow the caller’s stack.
See those constants and DIVERGENCE.md at the repository root.
This is a port of ts/src/*.ts, which is canonical, and a sibling of
the Go port in go/. See AGENTS.md.
Re-exports§
pub use ast::resolve_references;pub use ast::to_ast;pub use block::MAX_CONTAINER_NESTING;pub use html::render_html;pub use html::render_html_with;pub use html::DISALLOWED_TAGS;pub use inline::MAX_INLINE_NESTING;pub use node::Align;pub use node::Definition;pub use node::DefinitionSite;pub use node::ListData;pub use node::ListType;pub use node::MdNode;pub use node::NodeId;pub use node::NodeType;pub use node::ReferenceType;pub use node::SourcePos;pub use node::TableAlign;pub use node::Tree;pub use node::WalkEvent;pub use node::Walker;pub use options::Options;pub use options::RefDef;pub use options::RefMap;pub use options::DEFAULT_OPTIONS;
Modules§
- ast
- Projection from the native CommonMark tree to the mdast-adjacent JSON
AST this package has always returned. Port of
ts/src/ast.tsandgo/ast.go; the three must agree node for node, sincetest/spec/*.tsvis the parity contract between them. - block
- Phase 1 of the CommonMark parse: block structure. Port of
ts/src/block.ts(canonical) andgo/block.go; keep the three in step, function for function. Spec 0.31.2, Appendix A “A parsing strategy”. - common
- Shared lexical helpers. Port of
ts/src/common.tsandgo/common.go: the character classes the spec names, backslash and entity unescaping (sections 6.1 and 6.2), link-label normalisation (section 4.7), and the URL and XML escaping the HTML renderer needs. - commonmark
- Engine-free entry point for the CommonMark parser. Port of
ts/src/commonmark.tsandgo/commonmark.go. - engine_
block - The engine-facing block driver: a custom lexer matcher that cuts the
source one physical line at a time, runs the shared block algorithm over
each line, and hands the engine the blocks that line opened and closed
as tokens; and the rule actions that build the AST from those tokens.
Port of
ts/src/engine-block.tsandgo/engineblock.go. - engine_
inline - The engine-facing inline driver: a second engine instance whose lexer
IS the inline scanner. Port of
ts/src/engine-inline.tsandgo/engineinline.go. - html
- HTML renderer for the finished CommonMark tree. Port of
ts/src/html.tsandgo/html.go; keep the three in step. - inline
- Phase 2 of the CommonMark parse (spec 0.31.2, Appendix A, “Phase 2:
inline structure”). Port of
ts/src/inline.ts(canonical) andgo/inline.go; keep the three in step. The block phase left the raw text of every paragraph and heading instring_content; this module turns that text into inline children and clears it. - node
- Native CommonMark node tree, the internal parse result. Port of
ts/src/node.tsandgo/node.go; keep the three in step. - options
- Types shared by both parse phases. Port of
ts/src/options.tsandgo/options.go.
Structs§
- Markdown
Error - The error a failed engine parse produces, re-exported so callers need not depend on the engine crate directly. The parser itself defines an output for every input; this is the engine’s own failure shape (a budget exceeded, a panic in another plugin’s callback).
- Tabnas
- Translation
Part - One optional alchemy translation source and its explicit entry point.
- Translation
Parts - The package-local structural translation interface.
Constants§
- PLUGIN_
NAME - The plugin’s name, as
Tabnas::use_pluginrecords it. - VERSION
- This crate’s version. It MUST equal
ts/package.json“version”: the release orchestrator rewrites both, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/markdown.tsandconst VERSIONingo/markdown.go.
Functions§
- lift_
text - Markdown’s lift,
alchemy/lift.alc, the file the manifest’stranslate.liftnames: a library of alchemy definitions, with noexport, whose entry pointmarkdown-liftreads a document’s events as a table’s records, the first row’s cells as the column labels and every later row as a record: the first table’s, or the empty table’s when the document holds none. A host links it with its own program. The crate embeds its own copy,translate/lift.alc, held to the file as the manifest’s is. - make
make_withunder the package defaults (gfmon,breaksoff).- make_
with - Build a tabnas engine with the Markdown plugin installed under the
given options. The Rust counterpart of
new Tabnas().use(Markdown, opts). - manifest_
text - The plugin’s manifest,
tabnas.plugin.json, as the repository carries it. Itstranslateobject is what a host that translates reads: the shapes Markdown is read as (records, through the lift, thentree) and written from (records), the root whose elements are the records (array), the tree its events carry (markdown-ast, the mdast-adjacent AST the reader builds, whose root is adocument, not mdast’sroot, and not a plain tree either), the files that hold the lift and the render, and the sentences that say what a translation does not keep. The crate embeds its own copy,translate/manifest.json, since a packaged crate holds nothing outsiders/;tests/translate_test.rsholds the copy to the file. - markdown
- Install the parser on a tabnas engine instance.
- parse
- Parse a Markdown source with the shared default engine instance.
- parse_
document - Parse Markdown to the mdast-adjacent JSON AST. References stay
unresolved, as mdast keeps them: a bracketed label is a
linkReferenceor animageReference, and each definition adefinitionnode where it stands.resolve_referencesresolves them. - parse_
inline - Parse a single run of inline Markdown, returning the inline children of the resulting paragraph. Empty when the text does not start with a paragraph.
- parse_
keep_ tree - Parse through the engine and also hand back the native tree the parse
built: the
keepTreehandshake the engine-path conformance harness uses, so it can render with the samerender_htmlthe engine-free path uses and isolate the parse from the rendering. - parse_
tree - Parse Markdown to the native CommonMark node tree.
- plugin
- The plugin descriptor, for
Tabnas::use_plugin. Options are read from the plugin option bag (gfm,breaks), so a caller who has one already can hand it over;markdownis the typed way in. - render_
text - Markdown’s render,
alchemy/render.alc, the file the manifest’stranslate.rendernames: a library of alchemy definitions, with noexport, whose entry pointmarkdown-renderwrites a table’s records as one GFM pipe table, and a table of no columns as the empty document. A host links it with its own program. The crate embeds its own copy,translate/render.alc, held to the file as the manifest’s is. - to_html
- Parse Markdown and render it to CommonMark-conformant HTML.
- transduce_
text - Markdown’s transducer part,
alchemy/transduce.alc, the file the manifest’stranslate.transducenames: a library of alchemy definitions, with noexport, whose entry pointmarkdown-transducewrites a document’s JSON events from the grammar’s rule passes, a block at a time, as the walk of the parser’s value writes them. A host that reads parser events links it with its own program. The crate embeds its own copy,translate/transduce.alc, held to the file as the manifest’s is. - translate
- Return Markdown’s immutable translation parts.