pub struct Document { /* private fields */ }Expand description
A parsed Markdown document.
Construct with Document::parse or Document::parse_with_options
and query with the accessors. Linting and formatting are operations
owned by their respective crates.
Document owns both the caller-supplied original bytes and the
canonical view pulldown parses against
(CM §2.1 line endings + CM §2.3 NUL → U+FFFD). The IR’s byte
ranges and semantic inventories see the canonical bytes; diagnostic
renderers and safe-fix application map those spans back to the
original.
Implementations§
Source§impl Document
impl Document
Sourcepub fn parse(source: &str) -> Result<Self, ParseError>
pub fn parse(source: &str) -> Result<Self, ParseError>
Parse source into the IR.
The library imposes no size cap; callers feeding untrusted
input are responsible for bounding source.len() themselves.
The mdwright CLI does this via --max-input-bytes (default
10 MB).
§Errors
Returns ParseError if parser execution cannot safely
recognise the canonicalised source.
Sourcepub fn parse_with_options(
source: &str,
opts: ParseOptions,
) -> Result<Self, ParseError>
pub fn parse_with_options( source: &str, opts: ParseOptions, ) -> Result<Self, ParseError>
Parse source under explicit recognition options.
§Errors
Returns ParseError if parser execution cannot safely
recognise the canonicalised source under opts.
Sourcepub fn parse_options(&self) -> ParseOptions
pub fn parse_options(&self) -> ParseOptions
Recognition policy used to build this document.
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
The canonical source string the IR was parsed against. Equal to the caller’s input when no CM §2.1 / §2.3 canonicalisation was needed; otherwise CRLF → LF and NUL → U+FFFD substitutions were applied.
Sourcepub fn original_source(&self) -> &str
pub fn original_source(&self) -> &str
The caller’s original source bytes, before CommonMark
line-ending and NUL canonicalisation.
Sourcepub fn canonical_to_original_range(&self, range: Range<usize>) -> Range<usize>
pub fn canonical_to_original_range(&self, range: Range<usize>) -> Range<usize>
Translate a canonical byte range into the caller’s original source coordinates.
Sourcepub fn line_index(&self) -> &LineIndex
pub fn line_index(&self) -> &LineIndex
Byte-offset → (line, column) translator.
Sourcepub fn prose_chunks(&self) -> &[TextSlice]
pub fn prose_chunks(&self) -> &[TextSlice]
Contiguous runs of prose text, with backslash escapes preserved. Each chunk is bounded by inline code, inline HTML, or a soft/hard line break; never crosses a code span.
Sourcepub fn autolinks(&self) -> &[AutolinkFact]
pub fn autolinks(&self) -> &[AutolinkFact]
CommonMark and GFM autolinks recognised in source order.
Sourcepub fn inline_codes(&self) -> &[InlineCode]
pub fn inline_codes(&self) -> &[InlineCode]
Inline code spans in source order. text excludes the
surrounding backticks; raw_range covers them.
Sourcepub fn math_regions(&self) -> &[MathRegion]
pub fn math_regions(&self) -> &[MathRegion]
TeX-style math regions detected in source (\[ … \],
\( … \), \begin{env} … \end{env}, optionally
$$ … $$ / $ … $). Lint rules that operate on prose
(e.g., latex-command) consult this slice to skip
diagnostics that fire inside math content. \alpha is
intentional inside \[ … \] and a bug outside it.
Sourcepub fn math_errors(&self) -> &[MathError]
pub fn math_errors(&self) -> &[MathError]
Recogniser errors (unmatched delimiter opens, unmatched
environment \begin). Surfaced by the math/unbalanced-delim
and math/unbalanced-env lint rules.
Sourcepub fn code_blocks(&self) -> &[CodeBlock]
pub fn code_blocks(&self) -> &[CodeBlock]
Fenced and indented code blocks in source order.
Sourcepub fn html_blocks(&self) -> &[HtmlBlock]
pub fn html_blocks(&self) -> &[HtmlBlock]
HTML blocks (CommonMark §4.6).
Sourcepub fn inline_html(&self) -> &[InlineHtml]
pub fn inline_html(&self) -> &[InlineHtml]
Inline HTML tags (open, close, self-closing, comment).
Sourcepub fn list_groups(&self) -> &[ListGroup]
pub fn list_groups(&self) -> &[ListGroup]
Lists in source order. Nested lists are separate entries.
Sourcepub fn list_tightness_view(&self) -> Vec<(&ListGroup, bool)>
pub fn list_tightness_view(&self) -> Vec<(&ListGroup, bool)>
Each ListGroup paired with the tree-derived tightness for
the matching structural list node. Pairing is by
raw_range.start, which is unique across lists in source
order.
Sourcepub fn link_defs(&self) -> Vec<LinkDef<'_>>
pub fn link_defs(&self) -> Vec<LinkDef<'_>>
Link reference definitions. Materialised on demand from the
document’s internal reference table; callers that hit this in a
hot loop should cache the result.
The returned slice borrows from self (not from source), so the
&str fields have the document’s borrow lifetime.
Sourcepub fn block_checkpoints(&self) -> &[BlockCheckpointFact]
pub fn block_checkpoints(&self) -> &[BlockCheckpointFact]
Top-level block checkpoints in canonical source coordinates.
Sourcepub fn link_like_ranges(&self) -> &[Range<usize>]
pub fn link_like_ranges(&self) -> &[Range<usize>]
Source ranges for links, images, and autolinks that should be treated as link-like regions by prose rules.
Sourcepub fn frontmatter(&self) -> Option<&Frontmatter>
pub fn frontmatter(&self) -> Option<&Frontmatter>
Frontmatter at the document head, if present. Carries both the
raw slice and a tag for which delimiter (YAML --- or TOML
+++) the source used.
Sourcepub fn suppressions(&self) -> &[Suppression]
pub fn suppressions(&self) -> &[Suppression]
Inline suppression directives parsed from <!-- mdwright: … -->
HTML comments. Returned in source order so linting and tooling
can show users where suppressions take effect.
Source§impl Document
impl Document
Sourcepub fn structural_spans(&self) -> &[StructuralSpan]
pub fn structural_spans(&self) -> &[StructuralSpan]
Recognised block/container ranges used as rewrite owners.
Sourcepub fn inline_delimiter_slots(
&self,
kind: InlineDelimiterKind,
) -> &[InlineDelimiterSlot]
pub fn inline_delimiter_slots( &self, kind: InlineDelimiterKind, ) -> &[InlineDelimiterSlot]
Inline emphasis/strong delimiter slots.
Sourcepub fn unordered_list_marker_sites(&self) -> &[UnorderedListMarkerSite]
pub fn unordered_list_marker_sites(&self) -> &[UnorderedListMarkerSite]
Unordered list item marker sites.
Sourcepub fn ordered_list_marker_sites(&self) -> &[OrderedListMarkerSite]
pub fn ordered_list_marker_sites(&self) -> &[OrderedListMarkerSite]
Ordered list item marker digit sites.
Sourcepub fn thematic_break_ranges(&self) -> &[Range<usize>]
pub fn thematic_break_ranges(&self) -> &[Range<usize>]
Thematic break source line ranges.
Sourcepub fn heading_attr_sites(&self) -> &[HeadingAttrSite]
pub fn heading_attr_sites(&self) -> &[HeadingAttrSite]
Heading attribute trailer sites.
Sourcepub fn inline_link_destination_slots(&self) -> &[InlineLinkDestinationSlot]
pub fn inline_link_destination_slots(&self) -> &[InlineLinkDestinationSlot]
Inline link/image destination slots.
Sourcepub fn reference_definition_sites(&self) -> &[ReferenceDefinitionSite]
pub fn reference_definition_sites(&self) -> &[ReferenceDefinitionSite]
Reference-definition destination ranges.
Sourcepub fn table_sites(&self) -> &[TableSite]
pub fn table_sites(&self) -> &[TableSite]
GFM table source rows and cell ranges.
Sourcepub fn wrappable_paragraphs(&self) -> &[WrappableParagraph]
pub fn wrappable_paragraphs(&self) -> &[WrappableParagraph]
Paragraph ranges and inline atomics for the wrap pass.