Expand description
tramlines-md: the markdown format of tramlines. It checks a markdown document against a schema, repairs it, and derives the scaffold a schema implies.
A schema is YAML in the vocabulary of the grammar: the core grammar of
tramlines-core, with the markdown format grammar laid on it, which adds
the sections, blocks and units a document of one kind must carry. The
engine parses the document, holds it to the schema and reports each
failure as a Finding. The items of tramlines-core are re-exported,
so a host needs this crate alone.
Compile a schema and check a document against it:
use tramlines_md::{
Locator, RepoPath,
check::{CheckOptions, NullHost, check_against},
document::Document,
grammar::{FormatRegistry, RegexCache, compile, load_grammar},
markdown::Dialect,
yaml,
};
let schema = "line-limit: 0\nsections:\n - heading: Groceries\n level: 1\n blocks:\n - kind: bullet-list\n each: { template: '${item:word} x${n:int}', example: Milk x2 }\n";
let schema = compile(
&yaml::parse(schema, 1)?,
&load_grammar()?,
&FormatRegistry::default(),
&RegexCache::new(),
&RepoPath::parse("/list.yaml").expect("a path"),
"list",
&Dialect::default(),
)
.expect("the schema compiles");
let text = "# Groceries\n\n- Milk x2\n- Bread\n";
let path = RepoPath::parse("/groceries.md").expect("a path");
let document = Document::parse(path, text, &Dialect::default());
let states = schema.states(document.frontmatter.as_ref());
let out = check_against(
document.view(),
&schema,
&states,
&NullHost,
CheckOptions::default(),
Locator::schema("list"),
);
assert_eq!(out.findings.len(), 1);
assert_eq!(out.findings[0].criterion, "TL_74");
assert_eq!(out.findings[0].line, Some(4));Modules§
- check
check_against: a document against a schema, every grammar rule key applied. What lies outside the document, the host answers throughHost.- derive
- The scaffold a schema implies, which is the only template of a document it has.
- document
- A document as the engine reads it on its own: its frontmatter and its body, parsed in a dialect, with nothing of a host.
- edit
- Repairs as edits: the engine’s own (bound units, headings, generated anchors) and a host’s, applied to a text in one pass.
- grammar
- The markdown format grammar on the core grammar, and the lowering of a schema in it. The core items are re-exported here.
- markdown
- Markdown parsing: blocks and units as the grammar reads them, the markers a host’s dialect spells, and heading slugs.
- text
- Checks of a scalar value that every format shares, and the English that a finding is written in: the article before a word and a count.
- yaml
- YAML 1.2 core-schema parsing as TL_13 and TL_14 read it.
Structs§
- Finding
- One line of the report.
- Locator
- Where in a schema the rule that failed sits: the
idof the schema, and the rule’srule-id, else its section and block position. A finding that a schema rule raises ends with it. - Repo
Path - A path relative to the repository root, which starts with
/and uses forward slashes. The path/is the root itself. - Repo
Root - The repository root on disk.
- Spanned
- A value with the line it starts on.
Enums§
- Error
- Errors produced by this crate.
- Severity
- How a finding is reported.
- Yaml
- A YAML 1.2 core-schema value.
- Yaml
Error - A construct the YAML dialect refuses (TL_14), or a syntax error, with its line.
Type Aliases§
- Result
- Convenience alias for results from this crate.