tree-sitter-html

repository·master·Indexed 42 days ago

https://github.com/tree-sitter/tree-sitter-html

An incremental HTML grammar for the tree-sitter parsing engine, following the HTML5 Spec. It provides a concrete syntax tree (CST) parser for high-performance syntax highlighting, code navigation, and structural analysis of HTML documents, with available Node.js bindings for version 0.23.2.

Tokens
357
Snippets
1
Records
3
Agent score
3%

What's inside tree-sitter-html

  1. Use tree-sitter-html in Node.js

    master

    The tree-sitter-html package provides Node.js bindings for the HTML grammar. It is designed to be compatible with both standard Node.js environments (via node-gyp-build) and Bun (via prebuilt .node files).

    Upon requiring the module, it exports the parser instance and an optional nodeTypeInfo object containing metadata about HTML node types.

    const Parser = require('tree-sitter');
    const HTML = require('tree-sitter-html');
    
    const parser = new Parser();
    parser.setLanguage(HTML);
    
    const tree = parser.parse('<div></div>');
    console.log(tree.rootNode.toString());