tree-sitter-html provides the HTML grammar for the Tree-sitter parsing system. It enables parsing HTML code into a concrete syntax tree, facilitating static analysis, syntax highlighting, and code transformation. The library is actively developed with regular updates, currently at version 0.23.2.
pip install tree-sitter tree-sitter-htmlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `tree-sitter` parser with the `tree-sitter-html` grammar and parse a basic HTML string into a syntax tree, then print its S-expression representation.
Ensure both `tree-sitter` and `tree-sitter-html` are installed: `pip install tree-sitter tree-sitter-html`.
Thoroughly test parsing results with your specific HTML structures after updating the grammar. Refer to GitHub issues for known parsing quirks.
Install all relevant language grammars for files containing multiple embedded languages: `pip install tree-sitter-html tree-sitter-javascript tree-sitter-css`.
Instead of `Language.build_library()`, directly pass the grammar's `language()` function to `tree_sitter.Language()`: `HTML_LANGUAGE = tree_sitter.Language(tree_sitter_html.language())`.