htmlwhitelist 0.5.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

Html Whitelist #

Build Status

Introduction #

This library can be used to whitelist html elements, attributes and attribute values.

The main purpose is to process html from an untrusted source and make sure that if the html is rendered by your application it doesn't contain elements that are not safe.

Usage #

import 'package:htmlwhitelist/htmlwhitelist.dart';

main() {
  var contents = '<b>See:</b> <a href="docs.html">the documentation</a>';
  var safe = Whitelist.simpleText.safeCopy(contents);


<b>See:</b> the documentation

If you have a DocumentFragment instead of a String you can use the Cleaner instead:

import 'package:htmlwhitelist/htmlwhitelist.dart';
import 'package:html/parser.dart';
import 'package:html/dom.dart';

main() {
  var contents = '<b>See:</b> <a href="docs.html">the documentation</a>';

  DocumentFragment fragment = parseFragment(contents);
  DocumentFragment safeCopy = Whitelist.simpleText.cleaner.safeCopy(fragment);



<b>See:</b> the documentation

License and contributors #

0.5.3 #

  • Update test dependency for Dart 2.0

0.5.2 #

  • Moving to Dart 2.0 compatibility

0.5.1 #

  • Added examples

0.5.0 #

  • Introduced strong mode

0.4.1 #

  • Added documentation to Uris
  • Tweaks in implementation

0.4.0 #

  • Added Uris class to contain various utility functions for inspecting and filtering uris
  • Restrict href in a and cite in blockquote and q to valid uris with the schemes blank, http or https
  • Only add rel="nofollow" for external references
  • Restrict src in img to valid uris with the schemes blank, http, https or data

0.3.0 #

  • Replaced AddAttribute by AttributeCollector for more flexibility in the generated attributes
  • Renamed forceAttribute to setAttribute to better reflect what it does
  • The originalAttributes are now in source order and unmodifiable

0.2.1 #

  • Tweaks in implementation

0.2.0 #

  • Added documentation
  • Added tests
  • Removed when from forceAttribute
  • Added when to Whitelist.tags, Whitelist.attributes and Whitelist.extraAttributes
  • Several minor improvements

0.1.0 #

  • Initial implementation


import 'package:htmlwhitelist/htmlwhitelist.dart';

void main() {
  var contents = '<b>See:</b> <a href="docs.html">the documentation</a>';
  var safe = Whitelist.simpleText.safeCopy(contents);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  htmlwhitelist: ^0.5.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:htmlwhitelist/htmlwhitelist.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/impl/whitelistimpl.dart. (-5.36 points)

Analysis of lib/src/impl/whitelistimpl.dart reported 11 hints, including:

line 15 col 33: Unnecessary new keyword.

line 24 col 50: Unnecessary new keyword.

line 25 col 8: Unnecessary new keyword.

line 25 col 34: Unnecessary new keyword.

line 36 col 7: Unnecessary new keyword.

Fix lib/src/impl/cleanerimpl.dart. (-2.48 points)

Analysis of lib/src/impl/cleanerimpl.dart reported 5 hints:

line 22 col 20: Unnecessary new keyword.

line 33 col 13: Unnecessary new keyword.

line 41 col 23: Unnecessary new keyword.

line 47 col 18: Unnecessary new keyword.

line 59 col 21: Unnecessary new keyword.

Fix lib/src/api/uris.dart. (-1 points)

Analysis of lib/src/api/uris.dart reported 2 hints:

line 55 col 19: Unnecessary new keyword.

line 82 col 46: Unnecessary new keyword.

Fix lib/src/impl/collector.dart. (-1 points)

Analysis of lib/src/impl/collector.dart reported 2 hints:

line 58 col 13: Unnecessary new keyword.

line 61 col 13: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (html).

Package is getting outdated. (-54.52 points)

The package was last published 80 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <3.0.0
html ^0.13.2+2 0.13.4+2 0.14.0+3
Transitive dependencies
charcode 1.1.3
collection 1.14.12
csslib 0.15.0 0.16.1
meta 1.1.8
path 1.6.4
source_span 1.7.0
term_glyph 1.1.0
utf 0.9.0+5
Dev dependencies
test ^1.3.0