Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
tree-sitter-rstml
Advanced tools
Readme
Rust + html grammar for the tree-sitter parser library.
Rust web frameworks, like Leptos, rely on JSX-style templates embedded inside Rust code using the rstml library. This project enables the parsing of those templates for various purposes, such as syntax highlighting in text editors.
Since rstml isn't a supposed to be a standalone language, there are two grammars defined for convenience:
rstml | rust_with_rstml | |
---|---|---|
Language | This grammar only parses the rstml template without requiring it to be wrapped in a view! macro invocation. | This grammar parses an entire rust source file as normal but will parse any view! macro invocations as a rstml template. |
Intended use | This is intended to be injected into the tree-sitter-rust grammar. This approach provides the most flexibility by allowing the user to configure what should be interpreted as an rstml macro. | In cases where tree-sitter injection is unsupported, this grammar is the best option. The macro invocation behaviour cannot be configured by the user. |
Example valid code |
<div>Hello, world</div> |
view! { <div>Hello, world</div> } |
Parser location | rstml/src | rust_with_rstml/src |
Rust binding usage |
Show codelet code = "<div>Hello, world</div>"; let mut parser = tree_sitter::Parser::new(); parser.set_language(tree_sitter_rstml::language_rstml()).expect("Error loading rstml grammar"); let tree = parser.parse(code, None).unwrap(); |
Show codelet code = r#" view! { <div>hello, world</div> } "#; let mut parser = tree_sitter::Parser::new(); parser.set_language(tree_sitter_rstml::language_rust_with_rstml()).expect("Error loading rust_with_rstml grammar"); let tree = parser.parse(code, None).unwrap(); |
JavaScript binding usage |
Show codeconst Parser = require('tree-sitter') const code = '<div>Hello, world</div>' const parser = new Parser() parser.setLanguage(require('tree-sitter-rstml').rstml) const tree = parser.parse(code) |
Show codeconst Parser = require('tree-sitter') const code = ` view! { <div>Hello, world</div> } ` const parser = new Parser() parser.setLanguage(require('tree-sitter-rstml').rust_with_rstml) const tree = parser.parse(code) |
Neovim's tree-sitter integration supports syntax highlighting, indentation, and code folding.
Without rstml highlighting | With rstml highlighting |
---|---|
To use the Neovim support with nvim-treesitter, you should:
"nvim-treesitter/nvim-treesitter"
is installed and configured correctly."rayliwell/tree-sitter-rstml"
plugin in your preferred package manager.require("tree-sitter-rstml").setup()
is ran after everytime nvim-treesitter
is loaded.Here's an example config using lazy.nvim:
require("lazy").setup({
{
"rayliwell/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "rust" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
{
"rayliwell/tree-sitter-rstml",
dependencies = { "nvim-treesitter" },
build = ":TSUpdate",
config = function ()
require("tree-sitter-rstml").setup()
end
},
})
Emacs' (29.1+) tree-sitter integration supports syntax highlighting and indentation.
Before (rust-ts-mode ) | After (rstml-ts-mode ) |
---|---|
Emacs support is provided by the rstml-ts-mode
package. Installation instructions can be found on the project's GitHub.
This project extends and heavily relies upon the tree-sitter-rust grammar. It would not be possible without its contributors, as well as those who have contributed to the wider tree-sitter ecosystem.
Additionally, this project is based on the work of the rstml library. Originating as a fork of syn-rsx, whose creator, unfortunately, has passed away.
Licensed under the MIT License.
Copyright © 2024 Ryan Halliwell
FAQs
Rust + html grammar for the tree-sitter parser library.
The npm package tree-sitter-rstml receives a total of 0 weekly downloads. As such, tree-sitter-rstml popularity was classified as not popular.
We found that tree-sitter-rstml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.