Skip to main content

Crate tree_sitter_htmlx

Crate tree_sitter_htmlx 

Source
Expand description

Tree-sitter grammar for HTMLX (expression-enhanced HTML)

HTMLX extends HTML with expression syntax commonly used in modern frontend frameworks like Svelte, Vue, and others.

§Features

  • Expression interpolation: {expression}
  • Shorthand attributes: {name} (equivalent to name={name})
  • Spread attributes: {...props}
  • Directive attributes: bind:value, on:click, class:active, etc.

§Example

use tree_sitter_htmlx::LANGUAGE;

let mut parser = tree_sitter::Parser::new();
parser.set_language(&LANGUAGE.into()).expect("Failed to load HTMLX grammar");

let source = r#"<div class="container" {hidden}>
  <p>{greeting}, {name}!</p>
  <button onclick={handleClick}>Click me</button>
</div>"#;

let tree = parser.parse(source, None).unwrap();
assert!(!tree.root_node().has_error());

Constants§

HIGHLIGHTS_QUERY
The syntax highlighting query for HTMLX.
LANGUAGE
The tree-sitter LanguageFn for HTMLX.
NODE_TYPES
The content of the [node-types.json] file for HTMLX.

Functions§

language
The tree-sitter language for HTMLX.