oxc_markdown_parser/lib.rs
1//! oxc-markdown-parser is a CommonMark + GFM (and eventually MDX v3) parser
2//! that produces a span-faithful, style-preserving typed AST, designed for building formatters.
3//!
4//! Parse behavior targets micromark (= CommonMark + GFM as GitHub renders it).
5//! Style facts are first-class AST fields;
6//! consumers slice the original source through spans instead of reading cooked values.
7//!
8//! ## Basic Usage
9//!
10//! ```rust
11//! use oxc_markdown_parser::{Allocator, Parser};
12//!
13//! let allocator = Allocator::default();
14//! let parser = Parser::new(&allocator, "# Hello\n");
15//! let ret = parser.parse();
16//! // Markdown mode is structurally diagnostic-free.
17//! assert!(ret.diagnostics.is_empty());
18//! ```
19
20pub mod ast;
21mod block;
22mod diagnostic;
23mod inline;
24mod options;
25mod parser;
26mod pos;
27mod syntax;
28
29pub use block::lexical;
30pub use diagnostic::{Diagnostic, DiagnosticKind};
31pub use inline::{LiteralKind, literal_kind};
32
33/// The delimiter-run rules a printer needs: flanking and pairing, the parser's own.
34pub mod attention {
35 pub use crate::inline::emphasis::{Pair, Run, classify, pairs};
36}
37pub use options::{Constructs, ParserOptions};
38pub use oxc_allocator::Allocator;
39pub use parser::{Parser, ParserReturn};
40pub use pos::{Segment, Span};
41pub use syntax::{decode, escapes_next, label, unicode};
42
43/// Size regression guards, in the spirit of oxc_ast's generated assertions:
44/// enums stay pointer-sized-plus-tag, and hot node types stay small.
45#[cfg(all(test, target_pointer_width = "64"))]
46mod size_asserts {
47 use crate::ast;
48
49 #[test]
50 fn sizes() {
51 // Both content enums:
52 // tag + arena Box (or an inline Copy payload of at most the same footprint).
53 assert_eq!(size_of::<ast::Block>(), 16);
54 assert_eq!(size_of::<ast::Inline>(), 16);
55 // The hottest inline node stays inline in the enum.
56 assert_eq!(size_of::<ast::Text>(), 12);
57 }
58}