Skip to main content

Crate striptags

Crate striptags 

Source
Expand description

§striptags — strip HTML tags from a string

Remove HTML tags from text, optionally keeping a set of allowed tags and/or replacing removed tags with a string. A faithful Rust port of the striptags npm package — the same <plaintext>/<html>/<comment> state machine, including its handling of comments, quoted attributes, and nested <. Zero dependencies and #![no_std].

use striptags::{strip_tags, strip_tags_with};

assert_eq!(strip_tags("<p>Hello <b>world</b></p>"), "Hello world");
assert_eq!(strip_tags_with("<p>Hi</p><a>x</a>", &["a"], ""), "Hi<a>x</a>");
assert_eq!(strip_tags_with("<p>Hi</p>", &[], "\n"), "\nHi\n");

For chunked input, StripTags keeps parser state across calls to feed.

Structs§

StripTags
A streaming HTML-tag stripper that preserves parser state across chunks, matching the npm package’s init_streaming_mode.

Functions§

strip_tags
Strip all HTML tags from html.
strip_tags_with
Strip HTML tags from html, keeping any tag whose (lower-cased) name is in allowed, and replacing each removed tag with replacement.