Expand description
The CompMD processor: parses, validates and expands documents written in CompMD (Component Markdown), as the CompMD specification (version 1, draft) describes.
It implements stages 1 to 4b, everything up to rendering, as the states of a Processor: parsing gives a
document’s tree, resolving loads its imports and binds every component name, validating checks it against the
signatures, loading gives the inputs their values and loads the data, and expanding makes the expanded
tree a renderer draws, for one render context; every stage adds its
diagnostics. Expressions follow the CompMD CEL profile, with the md. functions (spec §8.2).
The processor does no I/O: the caller hands it files, packs, remote and host data, and the time zones, through the
traits of host, so it runs anywhere, a browser among them.
use compmd::{ParseOptions, Processor};
let parsed = Processor::new("a.comp.md", ":: chart[Weekly installs] {src=installs.csv}\n")
.parse(&ParseOptions::default());
let json = serde_json::to_value(parsed.tree()).unwrap();
assert_eq!(json["children"][0]["type"], "componentLeaf");Re-exports§
pub use processor::Processor;
Modules§
- components
- The components a document can name (spec §6.3), for a tool that lists them: grouped by the file that defines them, each with its kind, its signature and where the document uses it.
- context
- The render context (spec §8.5): what a render depends on besides the document, its imports and its data.
- diagnostic
- Diagnostics (spec §10) in the machine form of spec §10.5.
- expand
- Stage 4b, evaluating (spec §8, §9, §11, §12.3): the expanded tree. Every
compmddefinition,if,each,valueand interpolation is replaced by what it produces;box, the input components and host-language components stay as nodes, their params evaluated. Then the layout checks (W114, W119) run on the result. - expanded
- The expanded tree (spec §12.3), what stage 4b makes of a document: content only, with every
compmddefinition,if,each,valueand interpolation replaced by what it produces. Components stay as nodes only where the processor renders them itself:box, the input components, and host-language components, with their params evaluated. - frontmatter
- What a document’s frontmatter gives a render (spec §2.1, §6, §8.6, §8.7), for a tool that shows it: the author’s
own fields (
md.doc), the settings undermd, each data import with what was loaded for it, and the inputs with their values. - hints
- Positional hints: what is at a place in a processed document’s text, and what it takes. An editor shows a hint beside the text and offers its completions; a language server makes its hovers and completions of the same hint.
- host
- What a host provides. The processor does no I/O: it reads the document’s files, the packs, remote and
host:data and the time zones through these traits, each on its own, so a stage takes only the ones it uses and a host can reuse an implementation, such as a pack store or a time zone database, in another host.()implements each as “none”, and maps implement the data traits for what a host holds in memory:HashMap<String, String>for files,HashMap<String, Vec<LoadedRelease>>for packs,HashMap<String, Fetched>for remote data by URL andHashMap<String, Json>for host data by source. - plain
- What a plain CommonMark and GFM renderer shows of a document (spec §14), for an editor that shows how a document degrades: the text through markdown-rs with GFM on and CompMD’s syntax off. Raw HTML is escaped and unsafe link protocols are dropped, as markdown-rs does by default.
- policy
- The host’s configuration of packs (spec §6.4, §15): which packs a document may import, how far each one’s code is trusted, the packs the host denies or left out, and the runtimes and libraries it provides component code (spec §7.6).
- processor
- The processor (spec §11), its stages as states: a
Processorgoes fromNewthroughParsed,Resolved,ValidatedandLoadedtoExpanded. Each stage takes the processor and gives it back in its next state, so the stages can only run in order; each state gives what its stage made, and every state the diagnostics so far. Each stage takes what it uses: the parse options; the host’s files and packs, and the ambient packs; the origins remote data may come from; the render context, and the host’s remote andhost:data; the expansion options. - tree
- The document tree (spec §12): mdast nodes for CommonMark and GFM, and CompMD’s own nodes.
- values
- What a param’s value may be (spec §5.1, §7.3, §9.4), as one definition per kind of value: its tokens, the forms it
takes besides them, and an example of those forms. Checking a value, the F009 message that says what a param
takes, the suggestion of a misspelt token, and the
params.jsona renderer checks itself against all read it, so a token or a form is written down once.
Structs§
- Ambient
- The packs every document imports, at the lowest priority (spec §6.3), and whether to report their names.
- Parse
Options - What a parse needs besides the text.
- Text
Edit - An edit of a document’s text: the code points
start..endof the text the processor last saw becametext.
Enums§
- Language
- A host language a binding covers: the first word of a definition fence, or a component file’s extension.