Skip to main content

extract_text_with_filter

Function extract_text_with_filter 

Source
pub fn extract_text_with_filter(
    html: &str,
    selector: &str,
) -> Result<Vec<String>, SsgError>
Expand description

Extract concatenated text content from every element matching selector, separating successive elements with a single space.

Returns the decoded text — &amp; becomes &, &lt; becomes <, and so on — matching the on-screen rendering rather than the raw HTML bytes. This is the right behaviour for search-index extraction (issue #525 AC4).

§Examples

use ssg::util::html_rewriter::extract_text_with_filter;

let html = "<h1>Hello</h1><h1>World</h1>";
let texts = extract_text_with_filter(html, "h1").unwrap();
assert_eq!(texts, vec!["Hello".to_string(), "World".to_string()]);

§Errors

Returns SsgError::Io if lol_html rejects the selector or fails while parsing the input.