Re-Highlight

δΈ­ζ–‡η‰ˆζœ¬

Re-Highlight is a powerful syntax highlighting rule interpreter, which is a sub-module of the Reqable project. Re-Highlight can highlight a text by simply defining a syntax file. And Re-Highlight has built-in syntax highlighting rules for dozens of programming languages, it is easy to make your text syntax highlighting in just a few lines of code.

The implementation code of Re-Highlight is all written in the Dart, translated from the highlightjs project. The implementation idea and inspiration of Re-Highlight come from the highlight.dart project. We are grateful for these great open-source projects. Due to some issues with the highlight.dart project and its discontinuation, this project was born.

πŸ‘πŸ‘πŸ‘ Re-Highlight has been synchronized with the latest version v11.9.0 of highlightjs and has passed all test cases.

Getting Started

final Highlight highlight = Highlight();
highlight.registerLanguages(builtinAllLanguages);

const languages = [
  'json',
  'python',
  // other language
];

// Highlight your text or code.
final HighlightResult result = _highlight.highlightAuto('Your text or code', languages);

// Define your styles.
final TextStyle defaultStyle = TextStyle();
final Map<String, TextStyle> yourTheme = rainbowTheme;

// Convert highlight result to TextSpan
final TextSpanRenderer renderer = TextSpanRenderer(defaultStyle, yourTheme);
result.render(renderer);
final TextSpan? span = renderer.span;

// Pass the span to your Text Widget or TextEditingController.

More codes please see example.

Principle and Build

The Re-Highlight project is divided into three parts: syntax highlighting rule interpreter, syntax highlighting rule files, and theme style files. The rule interpreter is located in the src directory, the syntax highlighting rule files are located in the lib\languages directory, and the theme style files are located in the lib\styles directory. The latter two are automatically generated based on the files in highlightjs and do not require manual modification.

  • Install gulp.
npm install gulp -g
  • Sync highlightjs modules.
git submodule update --remote --init
  • Auto generated rule files.
cd tool
npm install
gulp generate
  • Run unit-tests.
flutter test

The code in the syntax highlighting rule interpreter part is translated directly from highlightjs, and we have tried to keep the consistency of file structure, class names, function names, and code logic as much as possible to facilitate future upgrades and synchronization.

Issues and Features

The syntax and logic of Re-Highlight are strictly translated from the highlightjs project. If you find any syntax issues or need support for new languages, we suggest submitting them to highlightjs, and we will try to synchronize them as soon as possible.

If it's related to Dart or Flutter, it is welcome to submit an issue or PR in this project.

If you would like to sponsor this project, please consider sponsoring the highlightjs project first. If you still have the capacity, you can support us by purchasing a Reqable license.

Libraries

languages/lib/common
languages/lib/javascript
languages/lib/mathematica
languages/lib/php
languages/lib/typescript
re_highlight
styles/a11y-dark
styles/a11y-light
styles/agate
styles/all
styles/an-old-hope
styles/androidstudio
styles/arduino-light
styles/arta
styles/ascetic
styles/atom-one-dark
styles/atom-one-dark-reasonable
styles/atom-one-light
styles/base16/apathy
styles/base16/apprentice
styles/base16/ashes
styles/base16/atelier-cave
styles/base16/atelier-cave-light
styles/base16/atelier-dune
styles/base16/atelier-dune-light
styles/base16/atelier-estuary
styles/base16/atelier-estuary-light
styles/base16/atelier-forest
styles/base16/atelier-forest-light
styles/base16/atelier-heath
styles/base16/atelier-heath-light
styles/base16/atelier-lakeside
styles/base16/atelier-lakeside-light
styles/base16/atelier-plateau
styles/base16/atelier-plateau-light
styles/base16/atelier-savanna
styles/base16/atelier-savanna-light
styles/base16/atelier-seaside
styles/base16/atelier-seaside-light
styles/base16/atelier-sulphurpool
styles/base16/atelier-sulphurpool-light
styles/base16/atlas
styles/base16/bespin
styles/base16/black-metal
styles/base16/black-metal-bathory
styles/base16/black-metal-burzum
styles/base16/black-metal-dark-funeral
styles/base16/black-metal-gorgoroth
styles/base16/black-metal-immortal
styles/base16/black-metal-khold
styles/base16/black-metal-marduk
styles/base16/black-metal-mayhem
styles/base16/black-metal-nile
styles/base16/black-metal-venom
styles/base16/brewer
styles/base16/bright
styles/base16/brogrammer
styles/base16/brush-trees
styles/base16/brush-trees-dark
styles/base16/chalk
styles/base16/circus
styles/base16/classic-dark
styles/base16/classic-light
styles/base16/codeschool
styles/base16/colors
styles/base16/cupcake
styles/base16/cupertino
styles/base16/danqing
styles/base16/darcula
styles/base16/dark-violet
styles/base16/darkmoss
styles/base16/darktooth
styles/base16/decaf
styles/base16/default-dark
styles/base16/default-light
styles/base16/dirtysea
styles/base16/dracula
styles/base16/edge-dark
styles/base16/edge-light
styles/base16/eighties
styles/base16/embers
styles/base16/equilibrium-dark
styles/base16/equilibrium-gray-dark
styles/base16/equilibrium-gray-light
styles/base16/equilibrium-light
styles/base16/espresso
styles/base16/eva
styles/base16/eva-dim
styles/base16/flat
styles/base16/framer
styles/base16/fruit-soda
styles/base16/gigavolt
styles/base16/github
styles/base16/google-dark
styles/base16/google-light
styles/base16/grayscale-dark
styles/base16/grayscale-light
styles/base16/green-screen
styles/base16/gruvbox-dark-hard
styles/base16/gruvbox-dark-medium
styles/base16/gruvbox-dark-pale
styles/base16/gruvbox-dark-soft
styles/base16/gruvbox-light-hard
styles/base16/gruvbox-light-medium
styles/base16/gruvbox-light-soft
styles/base16/hardcore
styles/base16/harmonic16-dark
styles/base16/harmonic16-light
styles/base16/heetch-dark
styles/base16/heetch-light
styles/base16/helios
styles/base16/hopscotch
styles/base16/horizon-dark
styles/base16/horizon-light
styles/base16/humanoid-dark
styles/base16/humanoid-light
styles/base16/ia-dark
styles/base16/ia-light
styles/base16/icy-dark
styles/base16/ir-black
styles/base16/isotope
styles/base16/kimber
styles/base16/london-tube
styles/base16/macintosh
styles/base16/marrakesh
styles/base16/materia
styles/base16/material
styles/base16/material-darker
styles/base16/material-lighter
styles/base16/material-palenight
styles/base16/material-vivid
styles/base16/mellow-purple
styles/base16/mexico-light
styles/base16/mocha
styles/base16/monokai
styles/base16/nebula
styles/base16/nord
styles/base16/nova
styles/base16/ocean
styles/base16/oceanicnext
styles/base16/one-light
styles/base16/onedark
styles/base16/outrun-dark
styles/base16/papercolor-dark
styles/base16/papercolor-light
styles/base16/paraiso
styles/base16/pasque
styles/base16/phd
styles/base16/pico
styles/base16/pop
styles/base16/porple
styles/base16/qualia
styles/base16/railscasts
styles/base16/rebecca
styles/base16/ros-pine
styles/base16/ros-pine-dawn
styles/base16/ros-pine-moon
styles/base16/sagelight
styles/base16/sandcastle
styles/base16/seti-ui
styles/base16/shapeshifter
styles/base16/silk-dark
styles/base16/silk-light
styles/base16/snazzy
styles/base16/solar-flare
styles/base16/solar-flare-light
styles/base16/solarized-dark
styles/base16/solarized-light
styles/base16/spacemacs
styles/base16/summercamp
styles/base16/summerfruit-dark
styles/base16/summerfruit-light
styles/base16/synth-midnight-terminal-dark
styles/base16/synth-midnight-terminal-light
styles/base16/tango
styles/base16/tender
styles/base16/tomorrow
styles/base16/tomorrow-night
styles/base16/twilight
styles/base16/unikitty-dark
styles/base16/unikitty-light
styles/base16/vulcan
styles/base16/windows-10
styles/base16/windows-10-light
styles/base16/windows-95
styles/base16/windows-95-light
styles/base16/windows-high-contrast
styles/base16/windows-high-contrast-light
styles/base16/windows-nt
styles/base16/windows-nt-light
styles/base16/woodland
styles/base16/xcode-dusk
styles/base16/zenburn
styles/brown-paper
styles/codepen-embed
styles/color-brewer
styles/dark
styles/default
styles/devibeans
styles/docco
styles/far
styles/felipec
styles/foundation
styles/github
styles/github-dark
styles/github-dark-dimmed
styles/gml
styles/googlecode
styles/gradient-dark
styles/gradient-light
styles/grayscale
styles/hybrid
styles/idea
styles/intellij-light
styles/ir-black
styles/isbl-editor-dark
styles/isbl-editor-light
styles/kimbie-dark
styles/kimbie-light
styles/lightfair
styles/lioshi
styles/magula
styles/mono-blue
styles/monokai
styles/monokai-sublime
styles/night-owl
styles/nnfx-dark
styles/nnfx-light
styles/nord
styles/obsidian
styles/panda-syntax-dark
styles/panda-syntax-light
styles/paraiso-dark
styles/paraiso-light
styles/pojoaque
styles/purebasic
styles/qtcreator-dark
styles/qtcreator-light
styles/rainbow
styles/routeros
styles/school-book
styles/shades-of-purple
styles/srcery
styles/stackoverflow-dark
styles/stackoverflow-light
styles/sunburst
styles/tokyo-night-dark
styles/tokyo-night-light
styles/tomorrow-night-blue
styles/tomorrow-night-bright
styles/vs
styles/vs2015
styles/xcode
styles/xt256