Dart library for unescaping HTML-encoded strings

Overview

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("<strong>This "escaped" 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 or while the small set only includes the first 255 charcodes.

Issues

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

Comments
  • Prepare for upcoming change to HttpRequest and HttpClientResponse

    Prepare for upcoming change to HttpRequest and HttpClientResponse

    An upcoming change to the Dart SDK will change HttpRequest and HttpClientResponse from implementing Stream<List<int>> to implementing Stream<Uint8List>.

    This forwards-compatible change prepares for that SDK breaking change by casting the Stream to List<int> before transforming it.

    https://github.com/dart-lang/sdk/issues/36900

    opened by tvolkert 1
  • Youtube Embed Video

    Youtube Embed Video

    Hi,

    Youtube embed is used in the incoming string. I can show the texts without any problem, but it just leaves spaces in the video part. Is there anything I should do in this situation?

    https://stackoverflow.com/questions/70850478/flutter-youtube-embed-problem-htmlunescape

    opened by sinanhaci 0
  • Fix pub.dev score

    Fix pub.dev score

    Low score: https://pub.dev/packages/html_unescape/versions/2.0.0-nullsafety.0/score

    Log: https://pub.dev/documentation/html_unescape/2.0.0-nullsafety.0/log.txt

    Seems to me that pub upgrade runs with flutter: 1.25.0-8.1.pre, which doesn't support the latest sdk constrains:

    ERR : The current Dart SDK version is 2.12.0-133.2.beta.
        | 
        | Because html_unescape requires SDK version >=2.12.0-133.7.beta <3.0.0, version solving failed.
    
    opened by nohli 0
  • Japanese unicode/unescape to text?

    Japanese unicode/unescape to text?

    I have a unicode unescape like this one

    \u30fb\ufeff\nTaylor Swift \u300eReady for it?\u300fWS\u6700\u7d42\u56de\ufeff\n\ufeff\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\u3041\u301c\u203c\ufe0f\ud83d\ude4c\ud83c\udffb\u2728\ufeff\n\ufeff\n\uff12\u6642\u9593\u307f\u3063\u3061\u308a\u8e8d\u308a\u8fbc\u307f\u307e\u3057\u305f\u306d\ud83d\udd25\ufeff\n\ufeff\n\u7686\u3055\u3093\u306e\u71b1\u610f\u3001\u96c6\u4e2d\u529b\u3001\u7d20\u6674\u3089\u3057\u304b\u3063\u305f\u3067\u3059\ud83d\udc4f\ud83c\udffb\ufeff\n\ufeff\n\u3042\u30681\u30f6\u6708\u534a\u30aa\u30ec\u30f3\u30b8\u3067\u306e\u30ec\u30c3\u30b9\u30f3\u3001\u9811\u5f35\u3063\u3066\u4e0b\u3055\u3044\ud83d\ude0a\ufeff\n\ufeff\n\u5927\u597d\u8a55\u3060\u3063\u305f\u306e\u3067\u65b0\u66f2\u3082\u4f01\u753b\u3057\u307e\u3059\u203c\ufe0f\ufeff\n\ufeff\n\u65e5\u7a0b\u3001\u307e\u305f\u8fd1\u65e5\u304a\u77e5\u3089\u305b\u81f4\u3057\u307e\u3059\uff01\uff01\ufeff\n\u304a\u697d\u3057\u307f\u306b\u2764\ufe0f\ufeff\n\ufeff

    And I want to convert to this, which is the actual text:

    Taylor Swift 『Ready for it?』WS最終回  お疲れ様でしたぁ〜‼️🙌🏻✨  2時間みっちり躍り込みましたね🔥  皆さんの熱意、集中力、素晴らしかったです👏🏻

    is that possible? this doesn't seem to accept this type of characters?

    opened by markgrancapal 0
  • Seems not to work

    Seems not to work

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

    I used the above, but it prints <strong>This "escaped" string will be printed normally.</strong>

    I was expecting This "escaped" string will be printed normally

    I'm on the latest flutter: Flutter Channel stable, v1.7.8+hotfix.2

    opened by ali-thowfeek 0
  • Quote replacing

    Quote replacing

    When I let it convert my raw json string it replaces & q u o t ; (had to write it like that so that Github doesn't convert it) with ", which destroys the json format and leads to deserialisation errors. You should implement a way to override certain replacements.

    opened by janoschp 0
Owner
Filip Hracek
@flutter and @dart-lang team member
Filip Hracek
Dart package for random strings and numbers, with weights

randomness Dart package for random strings and numbers, with weights Random strings, numbers. RNG with weights. Cryptographically secure options. Gett

null 2 Aug 6, 2022
A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

null 4 Sep 12, 2022
An alternative random library for Dart.

Randt Randt library for Dart... Description Use Randt to get a random integer from a list, generate random integer in a specific range and generate ra

Bangladesh Coding Soldierz 3 Nov 21, 2021
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

null 2 Oct 8, 2021
A comprehensive, cross-platform path manipulation library for Dart.

A comprehensive, cross-platform path manipulation library for Dart. The path package provides common operations for manipulating paths: joining, split

Dart 159 Dec 29, 2022
A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library.

polylabel Dart port of https://github.com/mapbox/polylabel. A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library

André Sousa 2 Nov 13, 2021
This is a dart library covering nearly 100% of the latest Planning Center public API.

Planning Center API for Dart Planning Center is an online platform for church management. It provides multiple apps for things like check-ins, service

null 1 Oct 6, 2022
A JMAP client library in Dart to make JMAP method calls and process the responses

JMAP Dart client A JMAP client library to make JMAP method calls and process the responses. We most notably use it to write the TMail Flutter applicat

LINAGORA 18 Dec 19, 2022
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Azka Full Snack Developer:) 73 Jan 7, 2023
A Pure Dart Utility library that checks for an Active Internet connection

This Code comes from https://github.com/komapeb/data_connection_checker * ?? Internet Connection Checker A Pure Dart Utility library that checks for a

Rounak Tadvi 61 Nov 25, 2022
Dart common utils library. DateUtil, EncryptUtil, JsonUtil, LogUtil, MoneyUtil, NumUtil, ObjectUtil, RegexUtil, TextUtil, TimelineUtil, TimerUtil.

Dart common utils library. DateUtil, EncryptUtil, JsonUtil, LogUtil, MoneyUtil, NumUtil, ObjectUtil, RegexUtil, TextUtil, TimelineUtil, TimerUtil.

null 1.3k Dec 22, 2022
Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.

Google 318 Dec 31, 2022
A library for Dart that generates fake data

faker A library for Dart that generates fake data. faker is heavily inspired by the Python package faker, and the Ruby package ffaker. Usage A simple

Jesper Håkansson 193 Dec 18, 2022
A Open Source Dart Library

A Open Source Dart Library

Debojyoti Singha 2 Apr 19, 2022
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Luke Pighetti 3.5k Jan 4, 2023
This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Eddie Genius 3 Dec 15, 2021
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!

Scribble Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more! A

Tim Created It. 73 Dec 16, 2022
A library for YAML manipulation with comment and whitespace preservation.

Yaml Editor A library for YAML manipulation while preserving comments. Usage A simple usage example: import 'package:yaml_edit/yaml_edit.dart'; void

Dart 17 Dec 26, 2022