Orientação gerada a partir de informações públicas. Apenas para referência.
Re-Highlight é uma biblioteca robusta do Flutter projetada para realçamento de sintaxe em texto, com suporte a múltidas linguagens de programação em todas as principais plataformas. Permite aos desenvolvedores renderizar código com colorização e formatação precisas, melhorando a legibilidade em editores de código, exibições de documentação ou aplicativos educacionais. Construída com foco em desempenho e personalização, integra-se perfeitamente em projetos Flutter com uma simples adição de pacote. A biblioteca utiliza análise eficiente e suporta atualizações dinâmicas de tema, tornando-a ideal para renderização em tempo real de código.
Casos de uso
widgets de editor de código
Visualizadores de documentação
Aplicativos educacionais de programação
Visualizações ao vivo do código
Exibição de texto consciente de sintaxe
Principais recursos
Suporte a múltiplos idiomas
Temas personalizáveis
Destaque em tempo real
Compatibilidade multiplataforma
Motor de análise leve
Mudança dinâmica de tema
Indicado para
Desenvolvedores construindo editores de código
Aplicativos que exigem renderização de texto sensível a sintaxe
Ferramentas educacionais com exemplos de código
Interfaces de documentação
Considerações
Pode exigir ajustes para blocos de código muito grandes
Detecção limitada de idioma embutida
A personalização do tema exige configuração manual
O desempenho depende do tamanho e da complexidade do texto
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Re-Highlight is a powerful syntax highlighter, 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.
The below shows the highlighting effect. For more styles and languages, please refer to example.
Getting Started
Add the followings in pubspec.yaml.
dependencies:re_highlight:^0.0.3
Highlight yout text or code.
finalHighlight highlight = Highlight();
highlight.registerLanguages(builtinAllLanguages);
const languages = [
'json',
'python',
// other language
];
// Highlight your text or code.finalHighlightResult result = _highlight.highlightAuto('Your text or code', languages);
// Define your styles.finalTextStyle defaultStyle = TextStyle();
finalMap<String, TextStyle> yourTheme = rainbowTheme;
// Convert highlight result to TextSpanfinalTextSpanRenderer renderer = TextSpanRenderer(defaultStyle, yourTheme);
result.render(renderer);
finalTextSpan? 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.
Used By
re-editor A powerful lightweight text and code editor widget.
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.
Sponsor
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.