搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

html_unescape

一個用於解碼HTML的小型函數庫。支援所有名稱字元參考、十進位字元參考和十六進位字元參考。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
46.2萬
喜歡數
181
Pub 分數
160

安裝套件

flutter pub add html_unescape

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量級的 Flutter/Dart 套件,用於解碼 HTML 標籤,包括名稱實體、十進位與十六進位字元參考。它能安全地將轉義的 HTML 文字轉換回原始形式,非常適合用於呈現來自網路來源或使用者輸入的內容。此套件高效、簡潔,專為在多個平台上的 Dart 應用中使用而設計。

適用情境

  • 在UI中渲染HTML編碼的文本
  • 處理使用者產生的內容
  • 從網路API解析資料
  • 從CMS顯示格式化文字
  • 在顯示前對輸入進行清理

主要特色

  • 支援所有 HTML 標示型態
  • 輕量且快速
  • 跨平台相容性
  • 簡單 API,方法明確
  • 無外部依賴

適合對象

  • 處理原始 HTML 字符串的應用程式
  • 內容渲染應用
  • Web 抓取工具
  • 文字處理工具
  • 教育類或文件類應用

使用建議

  • 不解析完整的HTML文件
  • 不適合用於XSS防護
  • 需要手動清理未轉義的內容
  • 限制字元參考解碼
  • 不適用於複雜的HTML操作

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

html_unescape

Build Status

A Dart library for unescaping HTML-encoded strings.

Supports:

  • Named Character References ( )
    • 2099 of them
  • Decimal Character References (á)
  • Hexadecimal Character References (ã)

The idea is that while you seldom need encoding to such a level (most of the time, all you need to escape is <, >, /, & and "), you do want to make sure that you cover the whole spectrum when decoding from HTML-escaped strings.

Inspired by Java's unbescape library.

Usage

A simple usage example:

import 'package:html_unescape/html_unescape.dart';

main() {
  var unescape = HtmlUnescape();
  var text = unescape.convert("&lt;strong&#62;This &quot;escaped&quot; string");
  print(text);
}

You can also use the converter to transform a stream. For example, the code below will transform a POSIX stdin into an HTML-unencoded stdout.

await stdin
    .transform(Utf8Decoder())
    .transform(HtmlUnescape())
    .transform(Utf8Encoder())
    .pipe(stdout);

Full versus small

If you're sure you will only encounter the most common escaped characters, you can import 'package:html_unescape/html_unescape_small.dart' instead of the full version. This will decrease code size and increase performance. The only difference is in the size of the Named Character Reference dictionary. The full set includes the likes of &DownLeftRightVector; or &UpArrowBar; while the small set only includes the first 255 charcodes.

Issues

Please use GitHub tracker. Don't hesitate to create pull requests, too.

所屬分類

原始碼儲存庫

使用此套件的專案

所在榜單