Skip to main content

Crate cssesc

Crate cssesc 

Source
Expand description

§cssesc — escape a string for CSS

Escape a string so it can be used as a CSS string or identifier (selector). A faithful Rust port of the widely-used cssesc npm package by Mathias Bynens.

use cssesc::cssesc;

assert_eq!(cssesc("Lady Bird"), "Lady Bird");
assert_eq!(cssesc("café"), "caf\\E9");
assert_eq!(cssesc("'quotes'"), "\\'quotes\\'");

Use cssesc_with / Options to escape an identifier, choose the quote style, wrap the output, or escape every character:

use cssesc::{cssesc_with, Options};

assert_eq!(cssesc_with("foo.bar", &Options::new().is_identifier(true)), "foo\\.bar");
assert_eq!(cssesc_with("1up", &Options::new().is_identifier(true)), "\\31up");

Zero dependencies and #![no_std].

Structs§

Options
Options for cssesc_with.

Enums§

Quotes
The quote style to escape for (and wrap with).

Functions§

cssesc
Escape string as a CSS string using the default options.
cssesc_with
Escape string with the given Options.