htmlwhitelist 0.5.3

Dart native js
Flutter Android iOS web

This library can be used to clean up html on the server. The main purpose is to convert html from an untrusted source to a version that's safe for rendering.

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
likes
90
pub points
18%
popularity

This library can be used to clean up html on the server. The main purpose is to convert html from an untrusted source to a version that's safe for rendering.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

r.spilker@gmail.com

License

MIT (LICENSE)

Dependencies

html

More

Packages that depend on htmlwhitelist