Search packages, repositories and app categories

Package detailsv2.0.0

html_unescape

A small library for un-escaping HTML. Supports all Named Character References, Decimal Character References and Hexadecimal Character References.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
462K
Likes
181
Pub points
160

Install package

flutter pub add html_unescape

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight Flutter/Dart package for decoding HTML entities, including named, decimal, and hexadecimal character references. It safely converts escaped HTML text back to its original form, making it ideal for rendering content from web sources or user input. The library is efficient, minimal, and designed specifically for use in Dart applications across multiple platforms.

Use cases

  • Rendering HTML-encoded text in UI
  • Processing user-generated content
  • Parsing data from web APIs
  • Displaying formatted text from CMS
  • Sanitizing input before display

Key features

  • Supports all HTML entity types
  • Lightweight and fast
  • Cross-platform compatibility
  • Simple API with clear methods
  • No external dependencies

Suitable for

  • Apps handling raw HTML strings
  • Content rendering apps
  • Web scraping utilities
  • Text processing tools
  • Educational or documentation apps

Considerations

  • Does not parse full HTML documents
  • Not suitable for XSS protection
  • Requires manual sanitization of unescaped content
  • Limited to character reference decoding
  • Not intended for complex HTML manipulation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package

Rankings