Textbringer Rouge
Rouge syntax highlighting integration for Textbringer.
This plugin integrates the Rouge syntax highlighter into Textbringer, automatically providing syntax highlighting for 200+ programming languages without needing to write regex patterns for each language.
Features
- 200+ Languages: Automatic syntax highlighting for all languages supported by Rouge
- Zero Configuration: Works out of the box - just install and open any supported file
- Smart Detection: Automatically detects the language from file extensions
- Fallback Support: Falls back to regex-based highlighting if Rouge fails
- Customizable: Override default token mappings and colors for any language
Installation
Install the gem by executing:
gem install textbringer-rougeOr add it to your Gemfile:
gem 'textbringer-rouge'Usage
The plugin is automatically loaded when you start Textbringer. Simply open any supported file and syntax highlighting will be applied automatically.
Supported Languages
Rouge supports 200+ languages including:
- Web: HTML, CSS, JavaScript, TypeScript, JSX, Vue, Svelte
- Programming: Ruby, Python, Java, C, C++, C#, Go, Rust, Swift, Kotlin
- Scripting: Bash, PowerShell, Perl, Lua, R
- Data: JSON, YAML, TOML, XML, CSV
- Markup: Markdown, reStructuredText, AsciiDoc
- Config: Nginx, Apache, Dockerfile, .gitignore
- And many more...
See the full list of supported languages.
Customization
You can customize the colors by modifying Textbringer faces in your ~/.textbringer.rb:
# Change string color
Textbringer::Face.define :string, foreground: "lightgreen"
# Change keyword color
Textbringer::Face.define :keyword, foreground: "lightblue", bold: true
# Change comment color
Textbringer::Face.define :comment, foreground: "gray", italic: trueDebug Mode
Enable debug logging to troubleshoot issues:
TEXTBRINGER_ROUGE_DEBUG=1 txtb your_file.rbDebug logs will be written to /tmp/rouge_adapter_debug.log.
How It Works
Textbringer Rouge uses a clever technique to integrate Rouge with Textbringer:
-
Window Monkey Patch: Extends
Window#highlightto support custom highlighting methods - RougeAdapter: A mixin module that provides Rouge-based highlighting for any Mode
- Token Mapping: Maps Rouge's semantic tokens to Textbringer's Face system
- Fallback: Falls back to regex-based highlighting if Rouge encounters errors
This approach maintains compatibility with existing Textbringer modes while adding powerful language support.
Development
After checking out the repo, run bundle install to install dependencies. Then, run rake test to run the tests.
To install this gem onto your local machine, run bundle exec rake install.
Running Tests
# Run all tests
bundle exec rake test
# Run a specific test file
bundle exec ruby -I lib:test test/textbringer/rouge_adapter_test.rbContributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yancya/textbringer-rouge.
License
The gem is available as open source under the terms of the WTFPL.
Credits
- Textbringer - The Emacs-like text editor in Ruby
- Rouge - The pure Ruby syntax highlighter