pub struct Document {
pub content: String,
pub path: PathBuf,
pub lines: Vec<String>,
pub book_src_dir: Option<PathBuf>,
}Expand description
Represents a parsed markdown document with position information
Fields§
§content: StringThe original markdown content
path: PathBufPath to the source file
lines: Vec<String>Lines split for line-based rule processing
book_src_dir: Option<PathBuf>Optional book source directory (used by mdbook rules for path resolution)
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(content: String, path: PathBuf) -> Result<Document, MdBookLintError>
pub fn new(content: String, path: PathBuf) -> Result<Document, MdBookLintError>
Parse a markdown document from content and path
Sourcepub fn with_book_src_dir(
content: String,
path: PathBuf,
book_src_dir: Option<PathBuf>,
) -> Result<Document, MdBookLintError>
pub fn with_book_src_dir( content: String, path: PathBuf, book_src_dir: Option<PathBuf>, ) -> Result<Document, MdBookLintError>
Parse a markdown document with an optional book source directory
The book_src_dir is used by mdbook rules (e.g., MDBOOK002) for resolving relative paths when running in preprocessor mode. When processing files directly from the filesystem, this can be None and the rules will discover the book source directory by looking for SUMMARY.md.
Sourcepub fn parse_ast<'a>(
&self,
arena: &'a Arena<Node<'a, RefCell<Ast>>>,
) -> &'a Node<'a, RefCell<Ast>>
pub fn parse_ast<'a>( &self, arena: &'a Arena<Node<'a, RefCell<Ast>>>, ) -> &'a Node<'a, RefCell<Ast>>
Parse the content into a comrak AST
Sourcepub fn parse_ast_with_context<'a>(
&self,
arena: &'a Arena<Node<'a, RefCell<Ast>>>,
) -> Result<&'a Node<'a, RefCell<Ast>>, MdBookLintError>
pub fn parse_ast_with_context<'a>( &self, arena: &'a Arena<Node<'a, RefCell<Ast>>>, ) -> Result<&'a Node<'a, RefCell<Ast>>, MdBookLintError>
Parse AST with error context
Sourcepub fn line_number_at_offset(&self, offset: usize) -> usize
pub fn line_number_at_offset(&self, offset: usize) -> usize
Get the line number (1-based) for a given byte offset
Sourcepub fn column_number_at_offset(&self, offset: usize) -> usize
pub fn column_number_at_offset(&self, offset: usize) -> usize
Get the column number (1-based) for a given byte offset
Sourcepub fn line_ending(&self, line: usize) -> Option<&str>
pub fn line_ending(&self, line: usize) -> Option<&str>
Return the source terminator for a 1-based logical line.
The returned value is "\n", "\r\n", or None when the line has no
terminator or does not exist. Rules that insert source lines should use
this instead of assuming LF.
Sourcepub fn headings<'a>(
&self,
ast: &'a Node<'a, RefCell<Ast>>,
) -> Vec<&'a Node<'a, RefCell<Ast>>>
pub fn headings<'a>( &self, ast: &'a Node<'a, RefCell<Ast>>, ) -> Vec<&'a Node<'a, RefCell<Ast>>>
Get all heading nodes from the AST
Sourcepub fn headings_with_context<'a>(
&self,
ast: &'a Node<'a, RefCell<Ast>>,
) -> Result<Vec<&'a Node<'a, RefCell<Ast>>>, MdBookLintError>
pub fn headings_with_context<'a>( &self, ast: &'a Node<'a, RefCell<Ast>>, ) -> Result<Vec<&'a Node<'a, RefCell<Ast>>>, MdBookLintError>
Get all heading nodes with error context
Sourcepub fn code_blocks<'a>(
&self,
ast: &'a Node<'a, RefCell<Ast>>,
) -> Vec<&'a Node<'a, RefCell<Ast>>>
pub fn code_blocks<'a>( &self, ast: &'a Node<'a, RefCell<Ast>>, ) -> Vec<&'a Node<'a, RefCell<Ast>>>
Get all code block nodes from the AST
Sourcepub fn code_blocks_with_context<'a>(
&self,
ast: &'a Node<'a, RefCell<Ast>>,
) -> Result<Vec<&'a Node<'a, RefCell<Ast>>>, MdBookLintError>
pub fn code_blocks_with_context<'a>( &self, ast: &'a Node<'a, RefCell<Ast>>, ) -> Result<Vec<&'a Node<'a, RefCell<Ast>>>, MdBookLintError>
Get all code block nodes with error context
Sourcepub fn heading_level<'a>(node: &'a Node<'a, RefCell<Ast>>) -> Option<u32>
pub fn heading_level<'a>(node: &'a Node<'a, RefCell<Ast>>) -> Option<u32>
Get the heading level for a heading node
Sourcepub fn node_text<'a>(&self, node: &'a Node<'a, RefCell<Ast>>) -> String
pub fn node_text<'a>(&self, node: &'a Node<'a, RefCell<Ast>>) -> String
Get the text content of a node
Sourcepub fn node_position<'a>(
&self,
node: &'a Node<'a, RefCell<Ast>>,
) -> Option<(usize, usize)>
pub fn node_position<'a>( &self, node: &'a Node<'a, RefCell<Ast>>, ) -> Option<(usize, usize)>
Get the source position of a node
Sourcepub fn frontmatter_line_range(&self) -> Option<(usize, usize)>
pub fn frontmatter_line_range(&self) -> Option<(usize, usize)>
Detect a leading YAML frontmatter block.
Recognition matches comrak’s front-matter extension (configured in
Self::parse_ast with a --- delimiter): the block must begin on the
very first line of the document, its opening and closing delimiter lines
must each be exactly --- (no indentation, no trailing whitespace, no
extra dashes), and a closing delimiter must be present. Returns the
1-based, inclusive (start_line, end_line) of the block with the
delimiters included, or None when the document has no frontmatter.
Line-based rules use this to avoid treating frontmatter delimiters and YAML keys as Markdown headings or lists (see MD041, MD007).
Sourcepub fn frontmatter_ast_offset<'a>(
&self,
ast: &'a Node<'a, RefCell<Ast>>,
) -> usize
pub fn frontmatter_ast_offset<'a>( &self, ast: &'a Node<'a, RefCell<Ast>>, ) -> usize
Number of leading source lines that comrak folds into a front-matter node.
When frontmatter is present, comrak renumbers every following node as if
the document began at line 1, so the source positions reported for nodes
after the frontmatter are shifted up by the number of lines the
frontmatter occupied (delimiters plus a single trailing blank line). Add
this offset back to translate an AST line number into an index into
Self::lines. Returns 0 when the document has no frontmatter.