Expand description
Tree-sitter grammar for HTML following the WHATWG HTML Living Standard
This grammar provides spec-compliant HTML parsing including:
- Void elements (§13.1.2): area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr
- Raw text elements (§13.1.2.1): script, style
- Escapable raw text elements (§13.1.2.2): textarea, title
- Optional end tags (§13.1.2.4): Proper implicit closing
- Character references (§13.5): Named, decimal, and hex entities
§Example
use tree_sitter_htmlx_html::LANGUAGE;
let mut parser = tree_sitter::Parser::new();
parser.set_language(&LANGUAGE.into()).expect("Failed to load HTML grammar");
let source = r#"<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Welcome to <strong>HTML</strong>!</p>
<img src="logo.png" alt="Logo">
</body>
</html>"#;
let tree = parser.parse(source, None).unwrap();
assert!(!tree.root_node().has_error());Constants§
- HIGHLIGHTS_
QUERY - The syntax highlighting query for HTML.
- INJECTIONS_
QUERY - The injection query for HTML (for script/style content).
- LANGUAGE
- The tree-sitter
LanguageFnfor HTML. - NODE_
TYPES - The content of the node-types.json file for HTML.
Functions§
- language
- The tree-sitter language for HTML.