Tree-sitter based syntax highlighting plugin for Textbringer.
- Accurate syntax parsing with Tree-sitter
- Properly highlights Terraform/HCL
for,in, and function calls (which Rouge fails to recognize) - Emacs-style feature-based level control
- Customizable node mappings
gem 'textbringer-tree-sitter'The following parsers are automatically installed during gem install:
- ruby
- python
- javascript
- json
- bash
These are downloaded from Faveod/tree-sitter-parsers and placed in ~/.textbringer/parsers/{platform}/.
To skip automatic parser downloads (useful in offline or restricted environments), set the environment variable:
export TEXTBRINGER_TREE_SITTER_NO_DOWNLOAD=1
gem install textbringer-tree-sitterWhen this variable is set:
gem installwill skip automatic parser downloads- CLI commands (
get,get-all) will refuse to download with an error message - You can still manually place parsers in
~/.textbringer/parsers/{platform}/
Use the CLI tool to install additional parsers:
# List available parsers and their installation status
textbringer-tree-sitter list
# Install a specific parser (downloads prebuilt or builds from source)
# Also generates a node_map if one doesn't exist in the gem
textbringer-tree-sitter get hcl
textbringer-tree-sitter get markdown
# Install parser only, skip node_map generation
textbringer-tree-sitter get markdown --no-map
# Install all Faveod prebuilt parsers at once
textbringer-tree-sitter get-allParsers are stored in ~/.textbringer/parsers/{platform}/.
# Show parser directory
textbringer-tree-sitter pathOnce a parser is installed and a node_map exists for the language, syntax highlighting is automatically enabled for the corresponding Mode (e.g., RubyMode, PythonMode, HCLMode).
The get command:
- Downloads or builds the parser
- Automatically generates a node_map if one doesn't exist in the gem
- Places the node_map in
~/.textbringer/tree_sitter/node_maps/
For custom Modes, call use_tree_sitter:
class MyMode < ProgrammingMode
extend Textbringer::TreeSitterAdapter::ClassMethods
use_tree_sitter :ruby
endYou can disable Tree-sitter highlighting for specific modes:
# Disable for RubyMode (falls back to default Textbringer highlighting)
RubyMode.tree_sitter_enabled = false
# Re-enable when needed
RubyMode.tree_sitter_enabled = trueYou can add languages not included in the gem by creating a configuration file.
textbringer-tree-sitter initThis creates ~/.textbringer/tree_sitter/languages.yml.
# Simple format (minimal config)
elixir:
repo: elixir-lang/tree-sitter-elixir
# Detailed format (full control)
zig:
repo: maxxnino/tree-sitter-zig
branch: master
commit: abc123 # Optional: pin to specific commit
subdir: "" # Optional: subdirectory within repo
build_cmd: "cc -shared -fPIC -O2 -I{src}/src {src}/src/parser.c -o {output}"
# Use a fork instead of curated version
ruby:
repo: my-username/tree-sitter-ruby
branch: experimental
# Use Faveod prebuilt parser
groovy:
source: faveodtextbringer-tree-sitter get elixirThe custom language will override any curated language with the same name.
textbringer-tree-sitter listThis shows both curated (built-in) and user-defined languages.
# ~/.textbringer.rb
# Level 1: comment, string only
# Level 2: + keyword, type, constant
# Level 3: + function_name, variable, number (default)
# Level 4: + operator, punctuation, builtin
CONFIG[:tree_sitter_highlight_level] = 4CONFIG[:tree_sitter_enabled_features] = [:comment, :string, :keyword]Textbringer::TreeSitter::NodeMaps.register(:ruby, {
my_custom_node: :keyword
})CONFIG[:tree_sitter_parser_dir] = "/path/to/your/parsers"These parsers are available from Faveod and include node_maps in the gem:
| Language | Auto-installed on gem install |
Command |
|---|---|---|
| bash | ✅ | textbringer-tree-sitter get bash |
| c | textbringer-tree-sitter get c |
|
| c-sharp | textbringer-tree-sitter get c-sharp |
|
| cobol | textbringer-tree-sitter get cobol |
|
| embedded-template | textbringer-tree-sitter get embedded-template |
|
| groovy | textbringer-tree-sitter get groovy |
|
| haml | textbringer-tree-sitter get haml |
|
| html | textbringer-tree-sitter get html |
|
| java | textbringer-tree-sitter get java |
|
| javascript | ✅ | textbringer-tree-sitter get javascript |
| json | ✅ | textbringer-tree-sitter get json |
| pascal | textbringer-tree-sitter get pascal |
|
| php | textbringer-tree-sitter get php |
|
| python | ✅ | textbringer-tree-sitter get python |
| ruby | ✅ | textbringer-tree-sitter get ruby |
| rust | textbringer-tree-sitter get rust |
These parsers require building from source but include node_maps:
| Language | Command | Repository |
|---|---|---|
| HCL (Terraform) | textbringer-tree-sitter get hcl |
mitchellh/tree-sitter-hcl |
| YAML | textbringer-tree-sitter get yaml |
tree-sitter-grammars/tree-sitter-yaml |
| SQL | textbringer-tree-sitter get sql |
m-novikov/tree-sitter-sql |
These parsers require building from source and node_map generation:
| Language | Command | Note |
|---|---|---|
| Go | textbringer-tree-sitter get go |
Generates node_map in ~/.textbringer/tree_sitter/node_maps/ |
| TypeScript | textbringer-tree-sitter get typescript |
Generates node_map in ~/.textbringer/tree_sitter/node_maps/ |
| TSX | textbringer-tree-sitter get tsx |
Generates node_map in ~/.textbringer/tree_sitter/node_maps/ |
| Markdown | textbringer-tree-sitter get markdown |
Generates node_map in ~/.textbringer/tree_sitter/node_maps/ |
To regenerate a node_map manually:
textbringer-tree-sitter generate-map <language>WTFPL - See LICENSE for details.
See DISCLAIMER for details.