pub struct TableUtils;Expand description
Shared table detection utilities
Implementations§
Source§impl TableUtils
impl TableUtils
Sourcepub fn is_potential_table_row_with_flavor(
line: &str,
flavor: MarkdownFlavor,
) -> bool
pub fn is_potential_table_row_with_flavor( line: &str, flavor: MarkdownFlavor, ) -> bool
Check if a line looks like a potential table row
Flavor-aware form of Self::is_potential_table_row
Under Obsidian, a line whose only pipes sit inside wikilink aliases is prose rather than a table row, so those pipes are masked before the check.
pub fn is_potential_table_row(line: &str) -> bool
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],
flavor: MarkdownFlavor,
) -> Vec<TableBlock>
pub fn find_table_blocks_with_code_info( content: &str, code_blocks: &[(usize, usize)], code_spans: &[CodeSpan], html_comment_ranges: &[ByteRange], flavor: MarkdownFlavor, ) -> 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
Pipes inside code spans are treated as content, 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.
The mask is the same byte width as what it replaces, so offsets into the masked string still address the original text.
Sourcepub fn mask_pipes_in_wikilinks(text: &str) -> String
pub fn mask_pipes_in_wikilinks(text: &str) -> String
Mask pipes inside wikilink aliases for accurate table cell parsing
In Obsidian, [[Target|Label]] renders Label as a link to Target, so
the pipe separates the two halves of one link rather than two table cells.
Only a pipe between [[ and a closing ]] on the same line is masked.
Two shapes are deliberately left as prose, because reading them as a link would merge cells in a table that is already well formed and so would report a column-count mismatch against a document that has none:
- Brackets inside an inline code span. Code binds tighter than links, so
`[[` | mid | `]]`is three cells of prose, not one cell with a link. - A blank link target.
[[ | ]]and[[|Label]]name no note, so the brackets are prose that happens to straddle a cell divider.
The mask is the same byte width as what it replaces, so offsets into the masked string still address the original text.
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)
This function only handles escaped pipes. Pipes inside inline code spans
are handled separately by mask_pipes_in_inline_code.
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.
Pipes inside code spans are treated as content, 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, flavor: MarkdownFlavor) -> bool
pub fn is_list_item_with_table_row(line: &str, flavor: MarkdownFlavor) -> 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.