pub struct CodeBlockUtils;Expand description
Utility functions for detecting and handling code blocks in Markdown documents
Implementations§
Source§impl CodeBlockUtils
impl CodeBlockUtils
Sourcepub fn is_in_code_block(content: &str, line_num: usize) -> bool
pub fn is_in_code_block(content: &str, line_num: usize) -> bool
Check if a line is inside a code block
Sourcepub fn is_code_block_delimiter(line: &str) -> bool
pub fn is_code_block_delimiter(line: &str) -> bool
Check if a line is a code block delimiter (start or end)
Sourcepub fn is_code_block_start(line: &str) -> bool
pub fn is_code_block_start(line: &str) -> bool
Check if a line is the start of a code block
Sourcepub fn is_code_block_end(line: &str) -> bool
pub fn is_code_block_end(line: &str) -> bool
Check if a line is the end of a code block
Sourcepub fn is_indented_code_block(line: &str) -> bool
pub fn is_indented_code_block(line: &str) -> bool
Check if a line is an indented code block (4+ columns of leading whitespace)
Sourcepub fn get_language_specifier(line: &str) -> Option<String>
pub fn get_language_specifier(line: &str) -> Option<String>
Extracts the language specifier from a fenced code block start line
This function parses the line that starts a fenced code block (using either ``` or ~~~) and extracts the language specifier that follows the fence markers.
§Parameters
line- The line of text that potentially contains a code block start with language specifier
§Returns
Some(String)- The language specifier if foundNone- If the line is not a code block start or has no language specifier
§Examples
use rumdl_lib::rules::code_block_utils::CodeBlockUtils;
let specifier = CodeBlockUtils::get_language_specifier("```rust");
assert_eq!(specifier, Some("rust".to_string()));
let specifier = CodeBlockUtils::get_language_specifier("~~~python");
assert_eq!(specifier, Some("python".to_string()));
let specifier = CodeBlockUtils::get_language_specifier("```");
assert_eq!(specifier, None);Sourcepub fn identify_code_block_lines(content: &str) -> Vec<bool>
pub fn identify_code_block_lines(content: &str) -> Vec<bool>
Identify which lines in the content are in code blocks
This function analyzes Markdown content and determines which lines are part of code blocks, including both fenced code blocks (``` or ~~~) and indented code blocks.
§Algorithm
- Iterates through each line of content
- Tracks state for fenced code blocks (toggled by fence delimiters)
- Detects indented code blocks (4 spaces or 1 tab)
- Handles nested code blocks appropriately
§Parameters
content- The full Markdown content to analyze
§Returns
A vector of boolean values with the same length as the number of lines in the input content. Each element indicates whether the corresponding line is inside a code block:
true- The line is inside a code blockfalse- The line is not inside a code block
§Examples
use rumdl_lib::rules::code_block_utils::CodeBlockUtils;
let content = "Some text\n```rust\nlet x = 1;\n```\nMore text";
let in_code_block = CodeBlockUtils::identify_code_block_lines(content);
assert_eq!(in_code_block, vec![false, true, true, true, false]);Auto Trait Implementations§
impl Freeze for CodeBlockUtils
impl RefUnwindSafe for CodeBlockUtils
impl Send for CodeBlockUtils
impl Sync for CodeBlockUtils
impl Unpin for CodeBlockUtils
impl UnsafeUnpin 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