Decode HTML encoded text in Dart

It seems that Dart does not provide a default mechanism (or at least could not find it) for decoding HTML-escaped objects.

What I would like to do is convert, for example. Q&A to Q&A . (This is just an example)

Starting with version 1.11.1, Dart converts encodes these in this way .

From there it’s quite simple to create an implementation of a custom converter, but this will not cover all use cases. For example: if if < expressed in hexadecimal value < ?

Has anyone gotten some great solution?

+8
dart decoder
source share
1 answer

I just made a small but complete Dart library for this purpose: html_unescape .

It supports:

  • Named character references (   )
    • 2099 of them
  • Decimal symbol references ( á )
  • References to hexadecimal characters ( ã )

Using sync

 import 'package:html_unescape/html_unescape.dart'; main() { var unescape = new HtmlUnescape(); var text = unescape.convert("<strong>This "escaped" string"); print(text); } 

Using Async

You can also use a converter to convert the stream. For example, the code below converts the POSIX stdin to HTML-unencoded stdout .

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

Additional information + documents in the pub .

+2
source share

All Articles