LintContext

Struct LintContext 

Source
pub struct LintContext<'a> {
Show 15 fields pub content: &'a str, pub line_offsets: Vec<usize>, pub code_blocks: Vec<(usize, usize)>, pub lines: Vec<LineInfo>, pub links: Vec<ParsedLink<'a>>, pub images: Vec<ParsedImage<'a>>, pub broken_links: Vec<BrokenLinkInfo>, pub footnote_refs: Vec<FootnoteRef>, pub reference_defs: Vec<ReferenceDef>, pub list_blocks: Vec<ListBlock>, pub char_frequency: CharFrequency, pub table_blocks: Vec<TableBlock>, pub line_index: LineIndex<'a>, pub flavor: MarkdownFlavor, pub source_file: Option<PathBuf>, /* private fields */
}

Fields§

§content: &'a str§line_offsets: Vec<usize>§code_blocks: Vec<(usize, usize)>§lines: Vec<LineInfo>§links: Vec<ParsedLink<'a>>§images: Vec<ParsedImage<'a>>§broken_links: Vec<BrokenLinkInfo>§footnote_refs: Vec<FootnoteRef>§reference_defs: Vec<ReferenceDef>§list_blocks: Vec<ListBlock>§char_frequency: CharFrequency§table_blocks: Vec<TableBlock>§line_index: LineIndex<'a>§flavor: MarkdownFlavor§source_file: Option<PathBuf>

Implementations§

Source§

impl<'a> LintContext<'a>

Source

pub fn new( content: &'a str, flavor: MarkdownFlavor, source_file: Option<PathBuf>, ) -> Self

Source

pub fn is_rule_disabled(&self, rule_name: &str, line_number: usize) -> bool

Check if a rule is disabled at a specific line number (1-indexed)

This method checks both persistent disable comments () and line-specific comments (, ).

Source

pub fn code_spans(&self) -> Arc<Vec<CodeSpan>>

Get code spans - computed lazily on first access

Source

pub fn math_spans(&self) -> Arc<Vec<MathSpan>>

Get math spans - computed lazily on first access

Source

pub fn is_in_math_span(&self, byte_pos: usize) -> bool

Check if a byte position is within a math span (inline $…$ or display $$…$$)

Source

pub fn html_comment_ranges(&self) -> &[ByteRange]

Get HTML comment ranges - pre-computed during LintContext construction

Source

pub fn html_tags(&self) -> Arc<Vec<HtmlTag>>

Get HTML tags - computed lazily on first access

Source

pub fn emphasis_spans(&self) -> Arc<Vec<EmphasisSpan>>

Get emphasis spans - pre-computed during construction

Source

pub fn table_rows(&self) -> Arc<Vec<TableRow>>

Get table rows - computed lazily on first access

Source

pub fn bare_urls(&self) -> Arc<Vec<BareUrl>>

Get bare URLs - computed lazily on first access

Source

pub fn has_mixed_list_nesting(&self) -> bool

Check if document has mixed ordered/unordered list nesting. Result is cached after first computation (document-level invariant). This is used by MD007 for smart style auto-detection.

Source

pub fn offset_to_line_col(&self, offset: usize) -> (usize, usize)

Map a byte offset to (line, column)

Source

pub fn is_in_code_block_or_span(&self, pos: usize) -> bool

Check if a position is within a code block or code span

Source

pub fn line_info(&self, line_num: usize) -> Option<&LineInfo>

Get line information by line number (1-indexed)

Source

pub fn line_to_byte_offset(&self, line_num: usize) -> Option<usize>

Get byte offset for a line number (1-indexed)

Source

pub fn get_reference_url(&self, ref_id: &str) -> Option<&str>

Get URL for a reference link/image by its ID (O(1) lookup via HashMap)

Source

pub fn get_reference_def(&self, ref_id: &str) -> Option<&ReferenceDef>

Get a reference definition by its ID (O(1) lookup via HashMap)

Source

pub fn has_reference_def(&self, ref_id: &str) -> bool

Check if a reference definition exists by ID (O(1) lookup via HashMap)

Source

pub fn is_in_list_block(&self, line_num: usize) -> bool

Check if a line is part of a list block

Source

pub fn list_block_for_line(&self, line_num: usize) -> Option<&ListBlock>

Get the list block containing a specific line

Source

pub fn is_in_code_block(&self, line_num: usize) -> bool

Check if a line is within a code block

Source

pub fn is_in_front_matter(&self, line_num: usize) -> bool

Check if a line is within front matter

Source

pub fn is_in_html_block(&self, line_num: usize) -> bool

Check if a line is within an HTML block

Source

pub fn is_in_code_span(&self, line_num: usize, col: usize) -> bool

Check if a line and column is within a code span

Source

pub fn is_byte_offset_in_code_span(&self, byte_offset: usize) -> bool

Check if a byte offset is within a code span

Source

pub fn is_in_reference_def(&self, byte_pos: usize) -> bool

Check if a byte position is within a reference definition This is much faster than scanning the content with regex for each check (O(1) vs O(n))

Source

pub fn is_in_html_comment(&self, byte_pos: usize) -> bool

Check if a byte position is within an HTML comment This is much faster than scanning the content with regex for each check (O(k) vs O(n)) where k is the number of HTML comments (typically very small)

Source

pub fn is_in_html_tag(&self, byte_pos: usize) -> bool

Check if a byte position is within an HTML tag (including multiline tags) Uses the pre-parsed html_tags which correctly handles tags spanning multiple lines

Source

pub fn is_in_jinja_range(&self, byte_pos: usize) -> bool

Check if a byte position is within a Jinja template ({{ }} or {% %})

Source

pub fn is_in_jsx_expression(&self, byte_pos: usize) -> bool

Check if a byte position is within a JSX expression (MDX: {expression})

Source

pub fn is_in_mdx_comment(&self, byte_pos: usize) -> bool

Check if a byte position is within an MDX comment ({/* … */})

Source

pub fn jsx_expression_ranges(&self) -> &[(usize, usize)]

Get all JSX expression byte ranges

Source

pub fn mdx_comment_ranges(&self) -> &[(usize, usize)]

Get all MDX comment byte ranges

Source

pub fn is_in_citation(&self, byte_pos: usize) -> bool

Check if a byte position is within a Pandoc/Quarto citation (@key or [@key]) Only active in Quarto flavor

Source

pub fn citation_ranges(&self) -> &[ByteRange]

Get all citation byte ranges (Quarto flavor only)

Source

pub fn is_in_shortcode(&self, byte_pos: usize) -> bool

Check if a byte position is within a Hugo/Quarto shortcode ({{< … >}} or {{% … %}})

Source

pub fn shortcode_ranges(&self) -> &[(usize, usize)]

Get all shortcode byte ranges

Check if a byte position is within a link reference definition title

Source

pub fn has_char(&self, ch: char) -> bool

Check if content has any instances of a specific character (fast)

Source

pub fn char_count(&self, ch: char) -> usize

Get count of a specific character (fast)

Source

pub fn likely_has_headings(&self) -> bool

Check if content likely contains headings (fast)

Source

pub fn likely_has_lists(&self) -> bool

Check if content likely contains lists (fast)

Source

pub fn likely_has_emphasis(&self) -> bool

Check if content likely contains emphasis (fast)

Source

pub fn likely_has_tables(&self) -> bool

Check if content likely contains tables (fast)

Source

pub fn likely_has_blockquotes(&self) -> bool

Check if content likely contains blockquotes (fast)

Source

pub fn likely_has_code(&self) -> bool

Check if content likely contains code (fast)

Check if content likely contains links or images (fast)

Source

pub fn likely_has_html(&self) -> bool

Check if content likely contains HTML (fast)

Source

pub fn blockquote_prefix_for_blank_line(&self, line_idx: usize) -> String

Get the blockquote prefix for inserting a blank line at the given line index. Returns the prefix without trailing content (e.g., “>” or “>>”). This is needed because blank lines inside blockquotes must preserve the blockquote structure. Returns an empty string if the line is not inside a blockquote.

Source

pub fn html_tags_on_line(&self, line_num: usize) -> Vec<HtmlTag>

Get HTML tags on a specific line

Source

pub fn emphasis_spans_on_line(&self, line_num: usize) -> Vec<EmphasisSpan>

Get emphasis spans on a specific line

Source

pub fn table_rows_on_line(&self, line_num: usize) -> Vec<TableRow>

Get table rows on a specific line

Source

pub fn bare_urls_on_line(&self, line_num: usize) -> Vec<BareUrl>

Get bare URLs on a specific line

Source

pub fn valid_headings(&self) -> ValidHeadingsIter<'_>

Get an iterator over valid CommonMark headings

This iterator filters out malformed headings like #NoSpace (hashtag-like patterns) that should be flagged by MD018 but should not be processed by other heading rules.

§Examples
use rumdl_lib::lint_context::LintContext;
use rumdl_lib::config::MarkdownFlavor;

let content = "# Valid Heading\n#NoSpace\n## Another Valid";
let ctx = LintContext::new(content, MarkdownFlavor::Standard, None);

for heading in ctx.valid_headings() {
    println!("Line {}: {} (level {})", heading.line_num, heading.heading.text, heading.heading.level);
}
// Only prints valid headings, skips `#NoSpace`
Source

pub fn has_valid_headings(&self) -> bool

Check if the document contains any valid CommonMark headings

Returns true if there is at least one heading with proper space after #.

Trait Implementations§

Source§

impl<'a> FilteredLinesExt for LintContext<'a>

Source§

fn filtered_lines(&self) -> FilteredLinesBuilder<'_>

Start building a filtered lines iterator Read more
Source§

fn content_lines(&self) -> FilteredLinesIter<'_>

Get an iterator over content lines only Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for LintContext<'a>

§

impl<'a> RefUnwindSafe for LintContext<'a>

§

impl<'a> Send for LintContext<'a>

§

impl<'a> Sync for LintContext<'a>

§

impl<'a> Unpin for LintContext<'a>

§

impl<'a> UnwindSafe for LintContext<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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