View Source z_css (zotonic_stdlib v1.19.0)

Utility functions for CSS processing. Also used for sanitizing HTML.

Summary

Functions

Parse a CSS binary or a token list. Return a parse tree of the css.
Sanitize a css string, remove all external URI references and injectable content.
Sanitize a css style tag, remove all external URI references and injectable content.
Tokenize a CSS string to binary, returns a list of tokens.

Types

-type charset() :: no_charset | {charset, string()}.
-type import() :: no_import | {import, Uri :: token(), medialist()}.
-type line() :: pos_integer().
-type media() :: [{ident, line(), string()}].
-type medialist() :: [media()].
-type rules() :: list().
-type stylesheet() :: {stylesheet, charset(), import(), rules()}.
-type tk() ::
    '{' | '}' | '[' | ']' | '(' | ')' | ',' | '.' | ':' | '/' | '-' | '+' | '*' | '>' | '=' |
    badcomment | includes | dashmatch | string | bad_string | ident | hash | import_sym |
    page_sym | media_sym | charset_sym | important_sym | ems | exs | length | angle | time |
    freq | dimension | percentage | number | uri | bad_uri | function | literal.
-type token() :: {tk(), line(), string()}.
-type tokens() :: [token()].

Functions

-spec parse(binary() | tokens()) -> {ok, stylesheet()} | {error, {line(), Error :: binary()}}.
Parse a CSS binary or a token list. Return a parse tree of the css.
-spec sanitize(Css :: binary()) ->
            {ok, Css :: binary()} | {error, {Line :: line(), Message :: binary()}}.
Sanitize a css string, remove all external URI references and injectable content.
-spec sanitize_style(Css :: binary() | string()) ->
                  {ok, Css :: binary()} | {error, {Line :: line(), Message :: binary()}}.
Sanitize a css style tag, remove all external URI references and injectable content.
-spec scan(string() | binary()) -> {ok, tokens()}.
Tokenize a CSS string to binary, returns a list of tokens.