defmodule AssertHTML do @moduledoc """ AssertHTML is an Elixir library for parsing and extracting data from HTML and XML with CSS. """ alias AssertHTML.{Matcher, Selector} @typedoc ~S""" CSS selector ## Supported selectors | Pattern | Description | |-----------------|------------------------------| | * | any element | | E | an element of type `E` | | E[foo] | an `E` element with a "foo" attribute | | E[foo="bar"] | an E element whose "foo" attribute value is exactly equal to "bar" | | E[foo~="bar"] | an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" | | E[foo^="bar"] | an E element whose "foo" attribute value begins exactly with the string "bar" | | E[foo$="bar"] | an E element whose "foo" attribute value ends exactly with the string "bar" | | E[foo*="bar"] | an E element whose "foo" attribute value contains the substring "bar" | | E[foo\|="en"] | an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en" | | E:nth-child(n) | an E element, the n-th child of its parent | | E:first-child | an E element, first child of its parent | | E:last-child | an E element, last child of its parent | | E:nth-of-type(n) | an E element, the n-th child of its type among its siblings | | E:first-of-type | an E element, first child of its type among its siblings | | E:last-of-type | an E element, last child of its type among its siblings | | E.warning | an E element whose class is "warning" | | E#myid | an E element with ID equal to "myid" | | E:not(s) | an E element that does not match simple selector s | | E F | an F element descendant of an E element | | E > F | an F element child of an E element | | E + F | an F element immediately preceded by an E element | | E ~ F | an F element preceded by an E element | """ @opaque css_selector :: String.t() @opaque html :: String.t() @type attributes :: [] @typedoc """ HTML element attribute name """ @type attribute_name :: String.t() | atom() @typep value :: String.t() defmacro __using__(_opts) do quote location: :keep do import AssertHTML end end @doc ~S""" Returns part of HTML by CSS selector ## Examples iex> html = ~S{