Skip to main content

strip_tags

Function strip_tags 

Source
pub fn strip_tags(html: &str) -> String
Expand description

Removes every tag and comment and keeps the text, escaped (Rails’ strip_tags).

<script> and <style> content is removed too. The result is HTML (&lt; stays escaped): insert it with |safe, or decode it for plain text.

§Examples

use ocre::security::strip_tags;

assert_eq!(strip_tags("<p>Hello <b>world</b>!</p><!-- note -->"), "Hello world!");
assert_eq!(strip_tags("<script>alert(1)</script>a &lt; b"), "a &lt; b");