Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

domelementtype

Shared enum of htmlparser2-style DOM node types.

A DOM tree built by parsers in this ecosystem tags every node with one of nine types: a document root, text, comments, directives, CDATA sections, doctypes, and three element kinds (Tag, Script, Style). This crate provides that enum, the stable lowercase string for each variant, and a predicate that reports whether a node is an element.

The crate is no_std, has no dependencies, and allocates nothing.

Installation

[dependencies]
domelementtype = "0.1"

Usage

use domelementtype::ElementType;

assert_eq!(ElementType::Tag.as_str(), "tag");
assert_eq!(ElementType::Cdata.as_str(), "cdata"); // lowercase, not "CDATA"

assert!(ElementType::Script.is_tag());
assert!(!ElementType::Comment.is_tag());

// Parse the interchange string back. Exact and case-sensitive.
assert_eq!("style".parse(), Ok(ElementType::Style));
assert!("STYLE".parse::<ElementType>().is_err());

is_tag is true for exactly three variants: Tag, Script, and Style.

ElementType implements Display (writing the same string as as_str) and FromStr (parsing it back). The parse is exact and case-sensitive, so "Tag" or " tag" returns an error.

Nine top-level constants (ROOT, TEXT, DIRECTIVE, COMMENT, SCRIPT, STYLE, TAG, CDATA, DOCTYPE) alias the matching variants for terse call sites.

License

Licensed under the MIT license.

About

Shared enum of htmlparser2-style DOM node types

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages