Skip to main content

rewrite_html

Function rewrite_html 

Source
pub fn rewrite_html<'h>(
    html: &str,
    handlers: Vec<(Cow<'h, Selector>, ElementContentHandlers<'h>)>,
) -> Result<String, SsgError>
Expand description

Run lol_html over html with the supplied (selector, handlers) pairs and return the rewritten document.

Maps any lol_html failure (selector parse error, encoder failure, memory-limit overflow) onto SsgError::Io with a synthetic <lol_html> path so callers don’t have to deal with lol_html’s error types directly.

§Examples

use ssg::util::html_rewriter::rewrite_html;

// With no handlers the output is byte-identical to the input.
let out = rewrite_html("<p>hi</p>", Vec::new()).unwrap();
assert_eq!(out, "<p>hi</p>");

§Errors

Returns SsgError::Io if lol_html rejects any selector or fails while writing output chunks.