搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

所在榜單