htmlwhitelist 0.5.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 7

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);
  print(safe);
}

prints

<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);

  print(safeCopy.outerHtml);
}

prints

<b>See:</b> the documentation

License and contributors

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

example/example.dart

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);
  print(safe);
}

Use this package as a library

1. Depend on it

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


dependencies:
  htmlwhitelist: ^0.5.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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';
  
Version Uploaded Documentation Archive
0.5.1 Jan 23, 2018 Go to the documentation of htmlwhitelist 0.5.1 Download htmlwhitelist 0.5.1 archive
0.5.0 Jan 23, 2018 Go to the documentation of htmlwhitelist 0.5.0 Download htmlwhitelist 0.5.0 archive
0.4.1 Jan 4, 2017 Go to the documentation of htmlwhitelist 0.4.1 Download htmlwhitelist 0.4.1 archive
0.4.0 Jan 4, 2017 Go to the documentation of htmlwhitelist 0.4.0 Download htmlwhitelist 0.4.0 archive
0.3.0 Dec 29, 2016 Go to the documentation of htmlwhitelist 0.3.0 Download htmlwhitelist 0.3.0 archive
0.2.1 Dec 28, 2016 Go to the documentation of htmlwhitelist 0.2.1 Download htmlwhitelist 0.2.1 archive
0.2.0 Dec 28, 2016 Go to the documentation of htmlwhitelist 0.2.0 Download htmlwhitelist 0.2.0 archive
0.1.0 Dec 20, 2016 Go to the documentation of htmlwhitelist 0.1.0 Download htmlwhitelist 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
7
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.3 <2.0.0