Skip to content
Tieson Trowbridge edited this page Apr 26, 2017 · 27 revisions

EX1: Allowing mailto: links

By default, only URIs that begin with http or https are allowed. This means that markup containing mailto links will have their URIs stripped when sanitized. To avoid this, add mailto as an allowed scheme:

var sanitizer = new HtmlSanitizer();
sanitizer.AllowedSchemes.Add("mailto");

EX2: Allowing data URIs

By default, only URIs that begin with http or https are allowed. This means that markup containing data-URI links will have their URIs stripped when sanitized. To avoid this, add data as an allowed scheme:

var sanitizer = new HtmlSanitizer();
sanitizer.AllowedSchemes.Add("data");

EX3 Replacing the default formatter

The default render mode for sanitized markup is HTML, which means void tags will be normalized to their non-self-closing version. If you require XML-style void tags, use an XhtmlMarkupFormatter:

var sanitizer = new HtmlSanitizer();
var formatter = AngleSharp.XHtml.XhtmlMarkupFormatter.Instance;
var content = "<p>This image is self-closing: <img src=\"some-image.png\" /></p>";
sanitizer.Sanitize(content, formatter);

Clone this wiki locally