htmlwhitelist 0.5.1

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

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

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
20 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
60
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • The description is too long.

    Search engines will display only the first part of the description. Try to keep it under 180 characters.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

    Run dartfmt to format lib/src/api/uris.dart.

    Run dartfmt to format lib/src/impl/cleanerimpl.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.3 <2.0.0
html ^0.13.2+2 0.13.3
Transitive dependencies
args 1.4.2
charcode 1.1.1
csslib 0.14.1
logging 0.11.3+1
path 1.5.1
source_span 1.4.0
utf 0.9.0+4
Dev dependencies
test ^0.12.30+1