Skip to content

Commit b0b1b54

Browse files
committed
Document tag! macro
Signed-off-by: Nico Burns <[email protected]>
1 parent c24fe6b commit b0b1b54

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

html5ever/src/tree_builder/rules.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ fn current_node<Handle>(open_elems: &[Handle]) -> &Handle {
3333
open_elems.last().expect("no current element")
3434
}
3535

36+
/// Helper macro that generates a [pattern](https://doc.rust-lang.org/reference/patterns.html) representing
37+
/// a [`Tag`] to make matching on [`Tag`]s less verbose.
38+
///
39+
/// This macro accepts 4 forms:
40+
///
41+
/// - `tag!(<div>)` where `div` can be any valid tag name. This matches a start tag where the tag name is "div".
42+
/// If the tag name contains characters other than [a-zA-Z0-9_] then it should be quoted a `<"div">`.
43+
/// - `tag!(</div>)` where `div` can be any valid tag name. This matches a end tag where the tag name is "div".
44+
/// If the tag name contains characters other than [a-zA-Z0-9_] then it should be quoted a `</"div">`.
45+
/// - `tag!(<>)`. This matches any start tag (regardless of tag name).
46+
/// - `tag!(</>)`. This matches any end tag (regardless of tag name).
47+
///
48+
/// Additionally any of the above can be freely combined with `|` to create an "or" match pattern.
49+
/// For example `tag!(<head> | </>)` will match a "head" start tag or any end tag.
3650
#[rustfmt::skip]
3751
macro_rules! tag {
3852
// Any start tag

0 commit comments

Comments
 (0)