tramlines_md/lib.rs
1//! tramlines-md: the markdown format of tramlines. It checks a markdown
2//! document against a schema, repairs it, and derives the scaffold a
3//! schema implies.
4//!
5//! A schema is YAML in the vocabulary of the grammar: the core grammar of
6//! tramlines-core, with the markdown format grammar laid on it, which adds
7//! the sections, blocks and units a document of one kind must carry. The
8//! engine parses the document, holds it to the schema and reports each
9//! failure as a [`Finding`]. The items of tramlines-core are re-exported,
10//! so a host needs this crate alone.
11//!
12//! **This crate is unstable.** It is at a 0.x version, and its interface can
13//! change in any release.
14//!
15//! Compile a schema and check a document against it:
16//!
17//! ```
18//! use tramlines_md::{
19//! Locator, RepoPath,
20//! check::{CheckOptions, NullHost, check_against},
21//! document::Document,
22//! grammar::{FormatRegistry, RegexCache, compile, load_grammar},
23//! markdown::Dialect,
24//! yaml,
25//! };
26//!
27//! 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";
28//! let schema = compile(
29//! &yaml::parse(schema, 1)?,
30//! &load_grammar()?,
31//! &FormatRegistry::default(),
32//! &RegexCache::new(),
33//! &RepoPath::parse("/list.yaml").expect("a path"),
34//! "list",
35//! &Dialect::default(),
36//! )
37//! .expect("the schema compiles");
38//!
39//! let text = "# Groceries\n\n- Milk x2\n- Bread\n";
40//! let path = RepoPath::parse("/groceries.md").expect("a path");
41//! let document = Document::parse(path, text, &Dialect::default());
42//! let states = schema.states(document.frontmatter.as_ref());
43//! let out = check_against(
44//! document.view(),
45//! &schema,
46//! &states,
47//! &NullHost,
48//! CheckOptions::default(),
49//! Locator::schema("list"),
50//! );
51//! assert_eq!(out.findings.len(), 1);
52//! assert_eq!(out.findings[0].criterion, "TL_74");
53//! assert_eq!(out.findings[0].line, Some(4));
54//! # Ok::<(), Box<dyn std::error::Error>>(())
55//! ```
56
57#![warn(missing_docs)]
58
59pub mod check;
60pub mod derive;
61pub mod document;
62pub mod edit;
63pub mod grammar;
64pub mod markdown;
65
66// sokf-implements: MD-9_AC-1
67// sokf-implements: MD-9_AC-3
68// sokf:begin reexports
69pub use tramlines_core::{
70 Error, Finding, Locator, RepoPath, RepoRoot, Result, Severity, Spanned, Yaml, YamlError, text,
71 yaml,
72};
73// sokf:end reexports