Element wrapper for the Sanitize.js library (a whitelist-based HTML sanitizer),
to use <marked-element>
.
<style>
.logo { width: 32px; }
</style>
<sanitize-element config='{
"elements": ["img"],
"attributes":{"img":["class","src"]},
"protocols":{"img":{"src":["https"]}}
}' sanitizer="{{sanitizer}}"></sanitize-element>
<marked-element sanitize sanitizer="[[sanitizer]]">
<div slot="markdown-html"></div>
<script type="text/markdown">
Markdown Image link `![image](url)`.
![WebComponents](https://web-components-resources.appspot.com/static/logo.svg)
You can set `class` like `<img class="logo">` and remove other attributes (e.g. onclick).
<img class="logo"
src="https://web-components-resources.appspot.com/static/logo.svg"
onclick="alert('WebComponents')">
Source block is escaped.
<img class="logo"
src="https://web-components-resources.appspot.com/static/logo.svg"
onclick="alert('WebComponents')">
</script>
</marked-element>
Other config like this.
<sanitize-element config='{
"elements":["a","img"],
"attributes":{"__ALL__":["class"], "a":["href","title"], "img":["src"]},
"protocols":{"a":{"href":["http","https"]}}
}' sanitizer="{{sanitizer}}"></sanitize-element>
<marked-element markdown="[[markdown]]" sanitize sanitizer="[[sanitizer]]">
<div slot="markdown-html"></div>
</markd-element>
Note: The config
attribute must be double quoted JSON.
First, make sure you have the Polymer CLI installed. Then run polymer serve
to serve your element locally.
$ polymer serve
$ polymer test
Your application is already set up to be tested via web-component-tester. Run polymer test
to run your application's test suite locally.