pub struct TransformContext<'arena> { /* private fields */ }Expand description
Context available to a pass while one document is being transformed.
The context only scans for URLs when a pass explicitly calls
TextRun::protected_url_ranges. It builds one reusable matcher from the
supplied renderer options, so disabled autolinks and custom prefixes match
the renderer exactly.
Implementations§
Source§impl<'arena> TransformContext<'arena>
impl<'arena> TransformContext<'arena>
Sourcepub fn new(
allocator: &'arena Allocator,
source: &'arena str,
renderer_options: &HtmlRendererOptions,
) -> Self
pub fn new( allocator: &'arena Allocator, source: &'arena str, renderer_options: &HtmlRendererOptions, ) -> Self
Creates a context for the exact source and allocator used to parse a document.
The caller must pass the same allocator and source that produced the document; the public AST does not retain either identity for validation. Renderer options are copied into one reusable URL matcher for the optional URL-protection helper. Construct the renderer from those same options (or an unchanged clone) so URL protection and output stay aligned. This matcher is not used unless a pass explicitly scans a text run.
Sourcepub fn alloc_str(&self, value: &str) -> &'arena str
pub fn alloc_str(&self, value: &str) -> &'arena str
Allocates a string that can be stored in this document’s AST.
Sourcepub fn replacement_text(&self, value: &str, span: Span) -> Text<'arena>
pub fn replacement_text(&self, value: &str, span: Span) -> Text<'arena>
Creates text for a replacement while preserving its original source span.
Sourcepub fn generated_text(&self, value: &str) -> Text<'arena>
pub fn generated_text(&self, value: &str) -> Text<'arena>
Creates text that was inserted without replacing source content.
Generated text uses Span::empty. This intentionally does not
distinguish generated content from a genuine empty source span.
Sourcepub fn replace_text_value(&self, text: &mut Text<'arena>, value: &str)
pub fn replace_text_value(&self, text: &mut Text<'arena>, value: &str)
Replaces a text node’s value and leaves its source span unchanged.
Sourcepub fn replace_text_range(
&self,
nodes: &mut Vec<'arena, Node<'arena>>,
node_range: Range<usize>,
byte_range: Range<usize>,
replacement: &str,
) -> Result<Span, TextReplacementError>
pub fn replace_text_range( &self, nodes: &mut Vec<'arena, Node<'arena>>, node_range: Range<usize>, byte_range: Range<usize>, replacement: &str, ) -> Result<Span, TextReplacementError>
Replaces a byte range within adjacent text nodes and returns its source span.
node_range selects one contiguous run from the nodes slice. The byte
range addresses the run’s coalesced text and must use UTF-8 boundaries.
Unchanged prefix and suffix text retain the source ranges of their
contributing nodes; replacement text receives the bounding span of the
source nodes it overlaps. A zero-width insertion receives an empty span.
If one parsed text node decodes to fewer bytes than its source spelling
(for example a character reference), every piece split from that node
keeps the full node span; this API does not provide character-level maps.