pub struct CodeBlockUtils;Expand description
Utility functions for detecting and handling code blocks in Markdown
Implementations§
Source§impl CodeBlockUtils
impl CodeBlockUtils
Sourcepub fn detect_code_blocks(content: &str) -> Vec<(usize, usize)>
pub fn detect_code_blocks(content: &str) -> Vec<(usize, usize)>
Detect all code blocks in the content (NOT including inline code spans)
Uses pulldown-cmark for spec-compliant CommonMark parsing. This correctly handles:
- Fenced code blocks (``` and ~~~)
- Indented code blocks (4 spaces or tab)
- Code blocks inside lists, blockquotes, and other containers
- Edge cases like backticks in info strings (which invalidate the fence)
Returns a sorted vector of (start, end) byte offset tuples.
Sourcepub fn detect_code_blocks_and_spans(content: &str) -> CodeRanges
pub fn detect_code_blocks_and_spans(content: &str) -> CodeRanges
Returns code block ranges and inline code span ranges in a single pulldown-cmark pass.
Sourcepub fn is_in_code_block_or_span(blocks: &[(usize, usize)], pos: usize) -> bool
pub fn is_in_code_block_or_span(blocks: &[(usize, usize)], pos: usize) -> bool
Check if a position is within a code block (for compatibility)
Sourcepub fn is_in_code_block(blocks: &[(usize, usize)], pos: usize) -> bool
pub fn is_in_code_block(blocks: &[(usize, usize)], pos: usize) -> bool
Check if a position is within a code block (NOT including inline code spans)
Sourcepub fn analyze_code_block_context(
lines: &[LineInfo],
line_idx: usize,
min_continuation_indent: usize,
) -> CodeBlockContext
pub fn analyze_code_block_context( lines: &[LineInfo], line_idx: usize, min_continuation_indent: usize, ) -> CodeBlockContext
Analyze code block context relative to list parsing This is the core function implementing Design #3’s three-tier classification
Sourcepub fn calculate_min_continuation_indent(
content: &str,
lines: &[LineInfo],
current_line_idx: usize,
) -> usize
pub fn calculate_min_continuation_indent( content: &str, lines: &[LineInfo], current_line_idx: usize, ) -> usize
Calculate minimum indentation required for code block to continue a list Based on the most recent list item’s marker width
Sourcepub fn detect_markdown_code_blocks(content: &str) -> Vec<MarkdownCodeBlock>
pub fn detect_markdown_code_blocks(content: &str) -> Vec<MarkdownCodeBlock>
Detect fenced code blocks with markdown/md language tag.
Returns a vector of MarkdownCodeBlock containing byte ranges for the
content between the fences (excluding the fence lines themselves).
Only detects fenced code blocks (``` or ~~~), not indented code blocks, since indented blocks don’t have a language tag.
Auto Trait Implementations§
impl Freeze for CodeBlockUtils
impl RefUnwindSafe for CodeBlockUtils
impl Send for CodeBlockUtils
impl Sync for CodeBlockUtils
impl Unpin for CodeBlockUtils
impl UnwindSafe for CodeBlockUtils
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