搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

所在榜单