Skip to main content

Document

Struct Document 

Source
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

Source

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.

Source

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.

Source

pub fn parse_options(&self) -> ParseOptions

Recognition policy used to build this document.

Source

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.

Source

pub fn original_source(&self) -> &str

The caller’s original source bytes, before CommonMark line-ending and NUL canonicalisation.

Source

pub fn canonical_to_original_range(&self, range: Range<usize>) -> Range<usize>

Translate a canonical byte range into the caller’s original source coordinates.

Source

pub fn line_index(&self) -> &LineIndex

Byte-offset → (line, column) translator.

Source

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.

CommonMark and GFM autolinks recognised in source order.

Source

pub fn inline_codes(&self) -> &[InlineCode]

Inline code spans in source order. text excludes the surrounding backticks; raw_range covers them.

Source

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.

Source

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.

Source

pub fn code_blocks(&self) -> &[CodeBlock]

Fenced and indented code blocks in source order.

Source

pub fn html_blocks(&self) -> &[HtmlBlock]

HTML blocks (CommonMark §4.6).

Source

pub fn inline_html(&self) -> &[InlineHtml]

Inline HTML tags (open, close, self-closing, comment).

Source

pub fn headings(&self) -> &[Heading]

ATX and setext headings with trimmed text and level.

Source

pub fn list_groups(&self) -> &[ListGroup]

Lists in source order. Nested lists are separate entries.

Source

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.

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.

Source

pub fn block_checkpoints(&self) -> &[BlockCheckpointFact]

Top-level block checkpoints in canonical source coordinates.

Source ranges for links, images, and autolinks that should be treated as link-like regions by prose rules.

Source

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.

Source

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

Source

pub fn structural_spans(&self) -> &[StructuralSpan]

Recognised block/container ranges used as rewrite owners.

Source

pub fn inline_delimiter_slots( &self, kind: InlineDelimiterKind, ) -> &[InlineDelimiterSlot]

Inline emphasis/strong delimiter slots.

Source

pub fn unordered_list_marker_sites(&self) -> &[UnorderedListMarkerSite]

Unordered list item marker sites.

Source

pub fn ordered_list_marker_sites(&self) -> &[OrderedListMarkerSite]

Ordered list item marker digit sites.

Source

pub fn thematic_break_ranges(&self) -> &[Range<usize>]

Thematic break source line ranges.

Source

pub fn heading_attr_sites(&self) -> &[HeadingAttrSite]

Heading attribute trailer sites.

Inline link/image destination slots.

Source

pub fn reference_definition_sites(&self) -> &[ReferenceDefinitionSite]

Reference-definition destination ranges.

Source

pub fn table_sites(&self) -> &[TableSite]

GFM table source rows and cell ranges.

Source

pub fn wrappable_paragraphs(&self) -> &[WrappableParagraph]

Paragraph ranges and inline atomics for the wrap pass.

Trait Implementations§

Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more