html_unescape 1.0.1+3
html_unescape #
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 = new 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(new Utf8Decoder())
.transform(new HtmlUnescape())
.transform(new 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_basic.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.
Changelog #
1.0.1+3 #
- Conform to upcoming change to HttpRequest and HttpClientResponse
1.0.1 #
- Upgrade to Dart 2
1.0.0 #
- Bump to 1.0. The package has baked for 2 years now.
0.1.5 #
- Remove deprecated dependency on
ChunkedConverter
(author: @andresaraujo) - Loosen dev dependency on path
older #
(No records. Please see commit history.)
// Copyright (c) 2018, Filip Hracek. All rights reserved. Use of this source
// code is governed by a BSD-style license that can be found in the LICENSE
// file.
import 'package:html_unescape/html_unescape.dart';
void main() {
var unescape = new HtmlUnescape();
print(unescape.convert("<strong>This "escaped" string "
"will be printed normally.</strong>"));
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
html_unescape: ^1.0.1+3
2. Install it
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter pub get
Alternatively, your editor might support pub get
or flutter pub get
.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:html_unescape/html_unescape.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
98
|
Health:
Code health derived from static analysis.
[more]
|
96
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
97
|
We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
Platforms
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:html_unescape/html_unescape.dart
.
Health suggestions
Fix lib/src/base.dart
. (-2.48 points)
Analysis of lib/src/base.dart
reported 5 hints:
line 29 col 9: Use contains instead of indexOf
line 31 col 24: Unnecessary new keyword.
line 56 col 23: Unnecessary new keyword.
line 86 col 14: Unnecessary new keyword.
line 88 col 12: Unnecessary new keyword.
Fix lib/src/data/named_chars_all.dart
. (-1 points)
Analysis of lib/src/data/named_chars_all.dart
reported 2 hints:
line 4 col 27: Avoid const keyword.
line 2105 col 29: Avoid const keyword.
Fix lib/src/data/named_chars_basic.dart
. (-1 points)
Analysis of lib/src/data/named_chars_basic.dart
reported 2 hints:
line 4 col 27: Avoid const keyword.
line 275 col 29: Avoid const keyword.