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§
- Strip
Tags - 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 inallowed, and replacing each removed tag withreplacement.