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 Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:htmlwhitelist/htmlwhitelist.dart.

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. (-7.95 points)

The package was last published 56 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.2
csslib 0.15.0 0.16.1
path 1.6.4
source_span 1.5.5
term_glyph 1.1.0
utf 0.9.0+5
Dev dependencies
test ^1.3.0