搜索插件、代码仓与 APP 分类

re_highlight 封面
插件详情v0.0.3

re_highlight

Re-Highlight 是一个功能强大的文本语法高亮库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
15.4万
喜欢数
24
Pub 分数
140

安装插件

flutter pub add re_highlight

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Re-Highlight 是一个强大的 Flutter 库,专为文本中的语法高亮而设计,支持所有主要平台上的多种编程语言。它使开发者能够准确地渲染代码并进行着色和格式化,从而提升代码编辑器、文档显示或教育类应用中的可读性。该库注重性能和自定义功能,通过简单的包添加即可无缝集成到 Flutter 项目中。它采用高效的解析技术,并支持动态主题更新,非常适合实时代码渲染。

适合场景

  • 代码编辑器小部件
  • 文档查看器
  • 教育类编程应用
  • 实时代码预览
  • 语法感知的文本显示

主要特点

  • 多语言支持
  • 可自定义的主题
  • 实时高亮
  • 跨平台兼容性
  • 轻量级解析引擎
  • 动态主题切换

适合对象

  • 开发代码编辑器的开发者
  • 需要语法感知文本渲染的应用程序
  • 带有代码示例的教育工具
  • 文档接口

使用建议

  • 可能需要为非常大的代码块进行调整
  • 有限的内置语言检测
  • 主题自定义需要手动配置
  • 性能取决于文本大小和复杂性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Re-Highlight

latest version

中文版本

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.

art

Getting Started

Add the followings in pubspec.yaml.

dependencies:
  re_highlight: ^0.0.3

Highlight yout text or code.

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.

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.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

所在榜单