Skip to content

Instantly share code, notes, and snippets.

@kasperpeulen
Last active Jul 20, 2016
Embed
What would you like to do?
Example of setInnerHtml configured so that all nodes are allowed.
<!doctype html>
<html>
<head>
<!--material design lite-->
<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.0/material.indigo-indigo.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script type="application/dart" src="main.dart"></script>
</body>
</html>
import 'dart:html';
main() {
// href tag will be removed without nodevalidator
DivElement defaultValidator = new DivElement()
..setInnerHtml('Go to <a href="http://www.google.com">www.google.com</a>');
// nothing will be removed with the TrustedNodeValidator
DivElement trustedValidator = new DivElement()
..setInnerHtml('Go to <a href="http://www.google.com">www.google.com</a>',
validator: new TrustedNodeValidator());
document.body
..append(trustedValidator)
..append(defaultValidator);
}
/// A [NodeValidator] which allows everything.
class TrustedNodeValidator implements NodeValidator {
bool allowsElement(Element element) => true;
bool allowsAttribute(element, attributeName, value) => true;
}
name: dart.html_Element.setInnerHtml
description: |
Example of setInnerHtml configured so that all nodes are allowed.
homepage: https://gist.github.com/kasperpeulen/fdf8012098d834e1d608
homepage: https://gist.github.com/kasperpeulen/fdf8012098d834e1d608
environment:
sdk: '>=1.0.0 <2.0.0'
body {
margin: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment