css_select

Values

pub fn parse_simple_selector(
  input: String,
) -> Result(selector.Selector, parser.ParseError)

Parse a CSS selector string into a Selector.

Returns an error if the input is not a valid simple selector (no combinators like >, +, ~, ).

If you need a parse many expressions it is recommended to use the parser module instead

css_select.parse_simple_selector("div#foo.bar")
// -> Ok(ElementSelector(Tag("div"), [Id("foo"), Class("bar")]))
pub const simple_match: fn(
  #(String, List(#(String, String))),
  selector.Selector,
) -> Bool

Check if an HTML element matches a parsed Selector.

The element is a tuple of the tag name and a list of attribute key-value pairs.

let element = #("div", [#("class", "foo bar"), #("id", "wibble")])
let assert Ok(selector) = css_select.parse_simple_selector("div#foo")
css_select.simple_match(element, selector)
// -> True
Search Document