Public API Surface

mdwright is a virtual workspace, not a facade crate. Command users install the mdwright package. Rust library users depend on the component crate that owns the capability they need.

The API is still pre-1.0. Import paths and operation shapes may change in minor releases under the pre-1.0 caveats.

Use mdwright as a library

A minimal embed that parses Markdown, runs the standard lint catalogue, and formats with defaults. Add the three crates to Cargo.toml:

[dependencies]
mdwright-document = "0.1"
mdwright-format = "0.1"
mdwright-lint = "0.1"

Then:

use mdwright_document::Document;
use mdwright_format::{FmtOptions, format_validated};
use mdwright_lint::{LintOptions, RuleSet};

fn main() -> anyhow::Result<()> {
    let source = "# Hello\n\nSee https://example.com for the spec.\n";

    // Parse once. `Document` holds source coordinates and recognised facts.
    let doc = Document::parse(source)?;

    // Lint with the shipped default rule set.
    let rules = RuleSet::stdlib_defaults();
    for diag in rules.check_with(&doc, LintOptions::default()) {
        println!("{}: {}", diag.rule, diag.message);
    }

    // Format. Returns a verified rewrite or a `FormatError` on safety-gate refusal.
    let formatted = format_validated(&doc, &FmtOptions::default())?;
    print!("{formatted}");
    Ok(())
}

The table below maps every capability to its owning crate. For the surface a particular crate exposes, follow its docs.rs link from the project README.

Common User Surfaces

CapabilityPublic surfaceOwning crate
Parse Markdown into stable factsDocument, ParseError, ParseOptionsmdwright-document
Configure Markdown recognitionExtensionOptions, GfmOptions, GfmAutolinkPolicy, MystOptions, PandocOptionsmdwright-document
Render Markdown to HTMLRenderOptions, RenderProfile, render_html, render_html_with_options, render_html_with_render_optionsmdwright-document
Format parsed or source MarkdownFmtOptions, WrapStrategy, FormatError, format_document, format_document_with_report, format_source, format_validated, format_validated_with_reportmdwright-format
Format editor rangesCheckpointTable, format_range, format_range_with_checkpointsmdwright-format
Compare formatter semanticssemantically_equivalent, first_divergencemdwright-format
Represent TeX and Unicode math-body diagnostics, vocabulary, Unicode layout, source translation, and outputLatexError, LatexErrorKind, SourceSpan, CommandInfo, CommandCategory, ArgumentShape, SupportStatus, lookup_command, latex_symbol, unicode_symbol_latex, unicode_super, unicode_sub, RenderedLatex, render_unicode_math, Translation, TranslationStatus, TranslationLoss, translate_latex_to_unicode, translate_unicode_to_latex, translate_latex_ranges_to_unicode, translate_unicode_ranges_to_latexmdwright-latex
Recognise Markdown math regionsscan_math_regions, render::convert_for_dollar, MathBody::source_rangemdwright-math
Run lint rulesRuleSet, LintOptionsmdwright-lint
Consume lint outputDiagnostic, Fix, Severity, Snippet, DuplicateRuleNamemdwright-lint
Apply safe lint fixesapply_safe_fixesmdwright-lint
Resolve configurationConfig, ConfigErrormdwright-config
Start the editor serverservemdwright-lsp
Build custom command binariesrun_with_rules, discover_markdownmdwright

Document is parse/query only. Linting, formatting, safe-fix application, config discovery, command delivery, and editor delivery stay in their owning crates.

The mdwright-latex surface targets common MathJax-style math bodies where Unicode can represent the source or terminal output honestly. Unicode-to-LaTeX translation is parser-backed for the supported subset: the crate lexes and parses Unicode mathematical source before emitting canonical LaTeX. It is not a TeX engine API, a browser layout API, or a diagram recogniser. Macro expansion, unsupported package commands, layout-heavy source, and unknown Unicode return typed errors, losses, or visible fallback output rather than hidden approximations.

Extension Surfaces

SurfaceUse
LintRuleImplement a downstream lint rule over &Document.
RuleSet::{new, add, remove, by_name, contains, iter, names, check, check_with}Compose standard and downstream rules.
mdwright_lint::stdlib::{defaults, all, by_name, names}Select standard rules for custom binaries or tests.
Diagnostic, Fix, Severity, SnippetReport lint findings and optional safe fixes.
rule_doc_url, docs_url, DOCS_URL_DEFAULTAttach stable documentation links to diagnostics.
InfoStringTypo::{new, with_extra}Extend the standard info-string vocabulary without forking the rule.
mdwright::run_with_rulesReuse the command package with a custom RuleSet.
mdwright::discover_markdownReuse command file-discovery policy in a custom command.

The standard rule structs under mdwright_lint::stdlib are public so callers can build precise RuleSets. Helper functions inside those rules are not public extension points unless listed above.

Advanced Document Facts

These facts are public because formatter, lint, audit, and custom-rule callers need stable source ranges without learning pulldown event shapes.

Fact familyPublic surface
Text and blocksTextSlice, InlineCode, CodeBlock, HtmlBlock, InlineHtml, Heading
Lists and referencesListGroup, ListItem, LinkDef
FrontmatterFrontmatter, FrontmatterDelimiter
AutolinksAutolinkFact, AutolinkOrigin
SuppressionsSuppression, SuppressionKind, AllowScope
PositionsLineIndex, LineIndexError, BlockCheckpointFact
MathMathRegion, MathSpan, MathError
Formatter factsStructuralSpan, StructuralKind, InlineDelimiterSlot, InlineDelimiterKind, UnorderedListMarkerSite, OrderedListMarkerSite, HeadingAttrSite, InlineLinkDestinationSlot, ReferenceDefinitionSite, TableSite, TableRowSite, TableCellSite, TableAlign, WrappableParagraph, ParagraphHardBreak

Formatter-facing facts expose accessors instead of public fields where practical. That keeps invalid construction out of downstream code while preserving stable ranges for rule authors and diagnostic tooling.

Not Public Surface

  • Root facade exports. There is no root package and no mdwright::{Document, FmtOptions, RuleSet} import path.
  • Parser internals, pulldown events, source/canonical byte-map internals, and the private document tree.
  • Source, CanonicalSource, OffsetMap, ByteSpan, OriginalSpan, NormalisedLabel, and heading trailer scanners.
  • Top-level block checkpoint parser helpers. Use mdwright_format::CheckpointTable.
  • Formatter rewrite candidates, rewrite snapshots, verification signatures, owner IDs, and byte-application internals.
  • mdwright-latex lexer tokens, parser cursors, AST nodes, command-registry storage, and Unicode layout internals.
  • Lint suppression maps, diagnostic sorting internals, and stdlib helper functions not listed as extension surfaces.
  • TOML raw schema structs and config discovery internals.
  • CLI and LSP state machines beyond the documented entry points.