pub struct HtmlRewriter<H> { /* private fields */ }html only.Expand description
A streaming, selector-driven HTML rewriter.
Feed input with write and finish with
end; the rewritten bytes accumulate in an internal buffer,
drained with take_output. Unmatched content passes
through byte-for-byte. For one-shot use, prefer rewrite_str.
Implementations§
Source§impl<H: ElementContentHandler> HtmlRewriter<H>
impl<H: ElementContentHandler> HtmlRewriter<H>
Sourcepub fn new(selectors: &[Selector], handler: H) -> Self
pub fn new(selectors: &[Selector], handler: H) -> Self
Creates a rewriter that runs handler for elements matching
selectors (the selector argument to the handler is the index into
this slice).
Sourcepub fn write(&mut self, chunk: &[u8]) -> Result<(), BoxError>
pub fn write(&mut self, chunk: &[u8]) -> Result<(), BoxError>
Feeds a chunk of input, appending rewritten bytes to the output.
§Errors
Surfaces a handler error, or a ParsingAmbiguityError if the input
is ambiguous for streaming parsing.
Sourcepub fn take_output(&mut self) -> Vec<u8> ⓘ
pub fn take_output(&mut self) -> Vec<u8> ⓘ
Removes and returns the rewritten output accumulated so far.
Sourcepub fn into_handler(self) -> H
pub fn into_handler(self) -> H
Consumes the rewriter, returning the handler (e.g. to read state accumulated during the rewrite).
Source§impl<'h> HtmlRewriter<ElementContentHandlers<'h>>
impl<'h> HtmlRewriter<ElementContentHandlers<'h>>
Sourcepub fn from_handlers(handlers: ElementContentHandlers<'h>) -> Self
pub fn from_handlers(handlers: ElementContentHandlers<'h>) -> Self
Creates a rewriter from a closure-based ElementContentHandlers.
Auto Trait Implementations§
impl<H> !RefUnwindSafe for HtmlRewriter<H>
impl<H> !UnwindSafe for HtmlRewriter<H>
impl<H> Freeze for HtmlRewriter<H>where
H: Freeze,
impl<H> Send for HtmlRewriter<H>where
H: Send,
impl<H> Sync for HtmlRewriter<H>where
H: Sync,
impl<H> Unpin for HtmlRewriter<H>where
H: Unpin,
impl<H> UnsafeUnpin for HtmlRewriter<H>where
H: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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