pub struct CodeBlock {
pub kind: CodeBlockKind<'static>,
pub language: Option<String>,
pub info_string: String,
pub attributes: Option<String>,
pub source: String,
pub byte_range: Range<usize>,
pub line_range: Range<usize>,
pub indent: usize,
}Expand description
A code block extracted from a Markdown document.
Fields§
§kind: CodeBlockKind<'static>The code block kind.
language: Option<String>First word from the fenced code block info string.
This is None for indented code blocks and for fenced code blocks
without an info string.
info_string: StringComplete fenced code block info string, without the opening backticks.
This is empty for indented code blocks.
attributes: Option<String>Remaining info string words after the language, if present.
source: StringCode block body.
byte_range: Range<usize>Byte range covering the opening marker, body, and closing marker.
line_range: Range<usize>Zero-based line range covering the opening marker, body, and closing marker.
indent: usizeWhitespace indentation before the opening marker.
Implementations§
Source§impl CodeBlock
impl CodeBlock
Sourcepub fn has_info_word(&self, word: &str) -> bool
pub fn has_info_word(&self, word: &str) -> bool
Returns true when the full info string contains word as a whitespace-separated token.
Sourcepub fn attributes(&self) -> impl Iterator<Item = &str>
pub fn attributes(&self) -> impl Iterator<Item = &str>
Returns fenced code block attributes as whitespace-separated tokens.
For ```rust a b c, this yields a, b, and c.
Sourcepub fn has_attribute(&self, attribute: &str) -> bool
pub fn has_attribute(&self, attribute: &str) -> bool
Returns true when the fenced code block attributes contain attribute.