marco-core
A Rust Markdown library for applications that need editor-quality accuracy — parse, render, and extract intelligence from Markdown.
You may be looking for:
Usage
[]
= "1.1"
use ;
let raw = b"# Hello\n\n**world**";
let clean = sanitize_input; // strips null bytes, fixes invalid UTF-8
let doc = parse?;
let html = render?;
// <h1 id="hello"><a class="marco-heading-anchor" href="#hello">Hello</a></h1>
// <p><strong>world</strong></p>
Skip expensive work for render-only pipelines:
use ;
let opts = ParseOptions ;
let doc = parse_with_options?;
let html = render?;
Customize rendering (syntax highlighting is on by default, "github" theme):
use RenderOptions;
let opts = RenderOptions ;
Editor intelligence:
use ;
let md = "# Heading\n\nA paragraph with **bold** text.\n";
let doc = parse?;
let mut provider = new;
provider.update_document;
let highlights = provider.highlights; // syntax highlight spans
let diagnostics = provider.diagnostics; // linting results
let completions = provider.completions; // context-aware suggestions
Features
Parse and render
- CommonMark — headings, lists, blockquotes, fenced/indented code blocks, links, images, emphasis, inline HTML, autolinks, thematic breaks, link references (full, shortcut, collapsed; Unicode casefold matching)
- GFM — tables, strikethrough (
~~text~~), task lists, footnotes, autolink literals, alerts/admonitions ([!NOTE],[!TIP],[!IMPORTANT],[!WARNING],[!CAUTION]) - Math — inline
$…$and display$$…$$via KaTeX - Diagrams — Mermaid fenced blocks
- Marco extensions:
- Block: sliders (
@slidestart…@slideendwith---/--separators and optional timer), tab blocks (:::tab/@tab Name), headerless tables (separator-first|---|---|), definition lists (Term\n: Definition) - Inline: mark/highlight (
==text==), superscript (^text^), subscript (~text~), subscript-arrow (˅text˅), dash-strikethrough (--text--), emoji shortcodes (:smile:→ 😄), inline footnotes (text^[note content]), platform mentions (@user[github]/@user[github](Display Name)), inline task checkboxes ([ ]/[x]), custom heading IDs (## Title {#my-id}) — all composable and nestable with each other and with standard CommonMark/GFM inline syntax
- Block: sliders (
Editor intelligence
- Syntax highlighting — per-node highlight tags;
compute_highlights_with_sourceadds extra tags for Marco syntax markers (tab block headers, slider separators) - Diagnostics/linting —
UnsafeLinkProtocol,UnresolvedLinkReference, and more; filter by severity withDiagnosticsOptions - Autocompletion — context-aware suggestions at cursor position
- Hover — returns info for links, headings, and other nodes at a given
Position - TOC extraction (
extract_toc), Markdown generation (generate_toc_markdown), and source insertion (replace_toc_in_text)
Reliability
- CommonMark spec conformance: 285/652 strict, 98.8% structural compliance
- UTF-8 sanitization (
&[u8]→String) strips null bytes and invalid sequences before parsing - GFM task list checkboxes and admonitions render as SVG icons (no CSS-only dependency)
- 662 tests — 649 integration, 13 doc/unit — all green
When to use marco-core
| Need | Recommended |
|---|---|
| Fast bulk processing (static sites, CI pipelines) | pulldown-cmark or comrak |
| Editor intelligence (highlights, linting, completions) | marco-core |
| CommonMark + GFM + math + diagrams | marco-core |
| Walk or transform the AST | marco-core |
| Minimal parse → render with no extras | pulldown-cmark |
Performance
Release build, 50-iteration mean:
| Input size | Parse | Render | End-to-end |
|---|---|---|---|
| ~1 KB | 5.0 µs | 1.2 µs | 6.2 µs |
| ~10 KB | 91.5 µs | 8.3 µs | 99.8 µs |
| ~100 KB | 2.1 ms | 86 µs | 2.2 ms |
Suitable for interactive editors and real-time linting.
Feature flags
All 8 flags are on by default. Use default-features = false to slim the build:
= { = "1.1", = false, = ["render-syntax-highlighting"] }
| Flag | Enables |
|---|---|
render-math |
KaTeX rendering |
render-diagrams |
Mermaid rendering |
render-syntax-highlighting |
Code block syntax highlighting |
file-logger |
Log rotation and file logging |
intelligence-highlights |
Syntax highlight tags |
intelligence-diagnostics |
Linting and diagnostics |
intelligence-completions |
Autocompletion |
intelligence-hover |
Hover information |
A --no-default-features build still includes parse + basic render.
Minimum Supported Rust Version
marco-core requires Rust 1.94.1 (stable). The MSRV is pinned in CI and will not change without a minor version bump.
Contributing
See CONTRIBUTING.md. Detailed guides:
- DEVELOPMENT.md — setup, workflow, coding rules
- TESTING.md — test inventory, CommonMark conformance
- TOOLS.md —
marco-astCLI,perf-labbenchmarking
License
MIT — see LICENSE.
Related: Marco is the GTK4 Markdown editor built on this crate.