pub struct TableUtils;Expand description
Shared table detection utilities
Implementations§
Source§impl TableUtils
impl TableUtils
Sourcepub fn is_potential_table_row(line: &str) -> bool
pub fn is_potential_table_row(line: &str) -> bool
Check if a line looks like a potential table row
Sourcepub fn is_delimiter_row(line: &str) -> bool
pub fn is_delimiter_row(line: &str) -> bool
Check if a line is a table delimiter row (e.g., |—|—|)
Sourcepub fn find_table_blocks_with_code_info(
content: &str,
code_blocks: &[(usize, usize)],
code_spans: &[CodeSpan],
html_comment_ranges: &[ByteRange],
) -> Vec<TableBlock>
pub fn find_table_blocks_with_code_info( content: &str, code_blocks: &[(usize, usize)], code_spans: &[CodeSpan], html_comment_ranges: &[ByteRange], ) -> Vec<TableBlock>
Find all table blocks in the content with optimized detection This version accepts code_blocks and code_spans directly for use during LintContext construction
Sourcepub fn find_table_blocks(
content: &str,
ctx: &LintContext<'_>,
) -> Vec<TableBlock>
pub fn find_table_blocks( content: &str, ctx: &LintContext<'_>, ) -> Vec<TableBlock>
Find all table blocks in the content with optimized detection This is a backward-compatible wrapper that accepts LintContext
Sourcepub fn count_cells(row: &str) -> usize
pub fn count_cells(row: &str) -> usize
Count the number of cells in a table row
Sourcepub fn count_cells_with_flavor(row: &str, flavor: MarkdownFlavor) -> usize
pub fn count_cells_with_flavor(row: &str, flavor: MarkdownFlavor) -> usize
Count the number of cells in a table row with flavor-specific behavior
For Standard/GFM flavor, pipes in inline code ARE cell delimiters (matches GitHub). For MkDocs flavor, pipes in inline code are NOT cell delimiters.
This function strips blockquote prefixes before counting cells, so it works correctly for tables inside blockquotes.
Sourcepub fn mask_pipes_in_inline_code(text: &str) -> String
pub fn mask_pipes_in_inline_code(text: &str) -> String
Mask pipes inside inline code blocks with a placeholder character
Sourcepub fn escape_pipes_in_inline_code(text: &str) -> String
pub fn escape_pipes_in_inline_code(text: &str) -> String
Escape pipes inside inline code blocks with backslash.
Converts | to \| inside backtick spans.
Used by auto-fix to preserve content while making tables valid.
Sourcepub fn mask_pipes_for_table_parsing(text: &str) -> String
pub fn mask_pipes_for_table_parsing(text: &str) -> String
Mask escaped pipes for accurate table cell parsing
In GFM tables, escape handling happens BEFORE cell boundary detection:
\|→ escaped pipe → masked (stays as cell content)\\|→ escaped backslash + pipe → NOT masked (pipe is a delimiter)
IMPORTANT: Inline code spans do NOT protect pipes in GFM tables!
The pipe in `a | b` still acts as a cell delimiter, splitting into
two cells: `a and b ``. This matches GitHub’s actual rendering.
To include a literal pipe in a table cell (even in code), you must escape it:
`a \| b` → single cell containing a | b (with code formatting)
Sourcepub fn split_table_row_with_flavor(
row: &str,
flavor: MarkdownFlavor,
) -> Vec<String>
pub fn split_table_row_with_flavor( row: &str, flavor: MarkdownFlavor, ) -> Vec<String>
Split a table row into individual cell contents with flavor-specific behavior.
Returns a Vec of cell content strings (not trimmed - preserves original spacing). This is the foundation for both cell counting and cell content extraction.
For Standard/GFM flavor, pipes in inline code ARE cell delimiters (matches GitHub). For MkDocs flavor, pipes in inline code are NOT cell delimiters.
Sourcepub fn split_table_row(row: &str) -> Vec<String>
pub fn split_table_row(row: &str) -> Vec<String>
Split a table row into individual cell contents using Standard/GFM behavior.
Sourcepub fn determine_pipe_style(line: &str) -> Option<&'static str>
pub fn determine_pipe_style(line: &str) -> Option<&'static str>
Determine the pipe style of a table row
Handles tables inside blockquotes by stripping the blockquote prefix before analyzing the pipe style.
Sourcepub fn extract_blockquote_prefix(line: &str) -> (&str, &str)
pub fn extract_blockquote_prefix(line: &str) -> (&str, &str)
Extract blockquote prefix from a line, returning (prefix, content).
This is useful for stripping the prefix before processing, then restoring it after.
For example: "> | H1 | H2 |" returns ("> ", "| H1 | H2 |").
Sourcepub fn extract_list_prefix(line: &str) -> (&str, &str, usize)
pub fn extract_list_prefix(line: &str) -> (&str, &str, usize)
Extract list marker prefix from a line, returning (prefix, content, content_indent).
This handles unordered list markers (-, *, +) and ordered list markers (1., 10), etc.)
Returns:
- prefix: The list marker including any leading whitespace and trailing space (e.g., “- “, “ 1. “)
- content: The content after the list marker
- content_indent: The number of spaces needed for continuation lines to align with content
For example:
"- | H1 | H2 |"returns("- ", "| H1 | H2 |", 2)"1. | H1 | H2 |"returns("1. ", "| H1 | H2 |", 3)" - table"returns(" - ", "table", 4)
Returns ("", line, 0) if the line doesn’t start with a list marker.
Sourcepub fn extract_table_row_content<'a>(
line: &'a str,
table_block: &TableBlock,
line_index: usize,
) -> &'a str
pub fn extract_table_row_content<'a>( line: &'a str, table_block: &TableBlock, line_index: usize, ) -> &'a str
Extract the table row content from a line, stripping any list/blockquote prefix.
This is useful for processing table rows that may be inside list items or blockquotes. The line_index indicates which line of the table this is (0 = header, 1 = delimiter, etc.)
Sourcepub fn is_list_item_with_table_row(line: &str) -> bool
pub fn is_list_item_with_table_row(line: &str) -> bool
Check if the content after a list marker looks like a table row. This is used to detect tables that start on the same line as a list marker.
Auto Trait Implementations§
impl Freeze for TableUtils
impl RefUnwindSafe for TableUtils
impl Send for TableUtils
impl Sync for TableUtils
impl Unpin for TableUtils
impl UnwindSafe for TableUtils
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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