Skip to main content

Crate tabnas_markdown

Crate tabnas_markdown 

Source
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.ts and go/ast.go; the three must agree node for node, since test/spec/*.tsv is the parity contract between them.
block
Phase 1 of the CommonMark parse: block structure. Port of ts/src/block.ts (canonical) and go/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.ts and go/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.ts and go/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.ts and go/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.ts and go/engineinline.go.
html
HTML renderer for the finished CommonMark tree. Port of ts/src/html.ts and go/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) and go/inline.go; keep the three in step. The block phase left the raw text of every paragraph and heading in string_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.ts and go/node.go; keep the three in step.
options
Types shared by both parse phases. Port of ts/src/options.ts and go/options.go.

Structs§

MarkdownError
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
TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.

Constants§

PLUGIN_NAME
The plugin’s name, as Tabnas::use_plugin records it.
VERSION
This crate’s version. It MUST equal ts/package.json “version”: the release orchestrator rewrites both, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/markdown.ts and const VERSION in go/markdown.go.

Functions§

lift_text
Markdown’s lift, alchemy/lift.alc, the file the manifest’s translate.lift names: a library of alchemy definitions, with no export, whose entry point markdown-lift reads 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_with under the package defaults (gfm on, breaks off).
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. Its translate object is what a host that translates reads: the shapes Markdown is read as (records, through the lift, then tree) 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 a document, not mdast’s root, 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 outside rs/; tests/translate_test.rs holds 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 linkReference or an imageReference, and each definition a definition node where it stands. resolve_references resolves 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 keepTree handshake the engine-path conformance harness uses, so it can render with the same render_html the 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; markdown is the typed way in.
render_text
Markdown’s render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point markdown-render writes 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’s translate.transduce names: a library of alchemy definitions, with no export, whose entry point markdown-transduce writes 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.