Skip to main content

extract_meta_tags

Function extract_meta_tags 

Source
pub fn extract_meta_tags(
    html_content: &str,
) -> Result<Vec<MetaTag>, MetadataError>
Expand description

Extracts every <meta> tag from an HTML document.

Walks the input in document order, yielding one MetaTag per <meta> element that carries both an identifying attribute (name, property, or http-equiv, in that fallback order) and a content attribute. Self-closing (<meta … />) and HTML-style (<meta …>) shapes are both accepted.

§Arguments

  • html_content - A string slice containing the HTML content to parse.

§Returns

Returns a Result containing a Vec<MetaTag> in document order if parsing reached the end of the input, or a MetadataError if the underlying scanner could not recover from a malformed region.

§Errors

Returns MetadataError::ExtractionError only when the input is so malformed that no further events can be produced. Per-element issues (missing content, unknown attributes, unrecognized escape) are tolerated silently.

§Implementation note

Backed by quick-xml configured in HTML-tolerant mode (mismatched end tags allowed, no DTD validation). This replaces the previous scraper / html5ever dependency tree, which dragged ~30 transitive crates including fxhash (RUSTSEC-2025-0057) and a vulnerable phf_generator / rand 0.8 path (RUSTSEC-2026-0097). See issue #22.