pub struct MathBody { /* private fields */ }Expand description
Math-body content with container prefixes hidden.
range is the outer body byte range (between the delimiters, in
source bytes). transparent lists byte ranges intersecting the
body that the consumer should treat as if they do not exist —
blockquote > markers and list-item continuation indentation
captured by the recogniser at scan time.
The abstraction lets callers consume math content without knowing
whether the region happened to be nested in a container. The
common case (no container) keeps the Cow::Borrowed fast path;
container-nested math allocates one String per region.
Implementations§
Source§impl MathBody
impl MathBody
pub fn new(range: Range<usize>, transparent: Box<[Range<usize>]>) -> Self
Sourcepub fn source_range(&self) -> Range<usize>
pub fn source_range(&self) -> Range<usize>
Source byte range of the delimiter-excluded math body.
Sourcepub fn as_str<'src>(&self, source: &'src str) -> Cow<'src, str>
pub fn as_str<'src>(&self, source: &'src str) -> Cow<'src, str>
Materialised body content with transparent runs removed.
Borrows the source slice when no runs intersect; allocates a
new String only when stripping is required.
Sourcepub fn clean_offset_to_source(&self, clean_off: usize) -> usize
pub fn clean_offset_to_source(&self, clean_off: usize) -> usize
Map a byte offset inside the clean (stripped) body back to a
source-absolute byte. Walks the same prefix iteration
Self::as_str uses, so an offset produced by a check on the
clean body resolves to the correct source position even when
container prefixes have been stripped.