Skip to main content

TransformContext

Struct TransformContext 

Source
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>

Source

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.

Source

pub const fn source(&self) -> &'arena str

Returns the source text parsed into the document.

Source

pub fn alloc_str(&self, value: &str) -> &'arena str

Allocates a string that can be stored in this document’s AST.

Source

pub fn replacement_text(&self, value: &str, span: Span) -> Text<'arena>

Creates text for a replacement while preserving its original source span.

Source

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.

Source

pub fn replace_text_value(&self, text: &mut Text<'arena>, value: &str)

Replaces a text node’s value and leaves its source span unchanged.

Source

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.

Auto Trait Implementations§

§

impl<'arena> !RefUnwindSafe for TransformContext<'arena>

§

impl<'arena> !Send for TransformContext<'arena>

§

impl<'arena> !Sync for TransformContext<'arena>

§

impl<'arena> !UnwindSafe for TransformContext<'arena>

§

impl<'arena> Forget for TransformContext<'arena>

§

impl<'arena> Freeze for TransformContext<'arena>

§

impl<'arena> Move for TransformContext<'arena>

§

impl<'arena> Unpin for TransformContext<'arena>

§

impl<'arena> UnsafeUnpin for TransformContext<'arena>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.