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 toname={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
LanguageFnfor HTMLX. - NODE_
TYPES - The content of the [
node-types.json] file for HTMLX.
Functions§
- language
- The tree-sitter language for HTMLX.