Skip to main content
Module

x/ammonia/mod.ts>AmmoniaBuilder

WASM bindings for the Ammonia HTML sanitizer
Latest
class AmmoniaBuilder
import { AmmoniaBuilder } from "https://deno.land/x/ammonia@0.3.1/mod.ts";

Properties

allowedClasses: Map<string, Set<string>>

Sets the CSS classes that are allowed on specific tags.

The values is structured as a map from tag names to a set of class names.

If the class attribute is itself whitelisted for a tag, then adding entries to this map will cause a panic.

Defaults

The set of allowed classes is empty by default.

cleanContentTags: Set<string>

The tags whose contents will be completely removed from the output.

Adding tags which are whitelisted in tags or tagAttributes will cause a panic.

Defaults

script, style
genericAttributePrefixes: Set<string> | null

Sets the prefix of attributes that are allowed on any tag.

Defaults

null

genericAttributes: Set<string>

Sets the attributes that are allowed on any tag.

Defaults

lang, title
idPrefix: string | null

Prefixes all "id" attribute values with a given string. Note that the tag and attribute themselves must still be whitelisted.

Defaults

null

linkRel: string | null

Configures a rel attribute that will be added on links.

If rel is in the generic or tag attributes, this must be set to null. Common rel values to include:

To turn on rel-insertion, call this function with a space-separated list. Ammonia does not parse rel-attributes; it just puts the given string into the attribute directly.

Defaults

"noopener noreferrer"

setTagAttributeValues: Map<string, Map<string, Set<string>>>

Sets the values of HTML attributes that are to be set on specific tags.

The value is structured as a map from tag names to a map from attribute names to an attribute value.

If a tag is not itself whitelisted, adding entries to this map will do nothing.

Defaults

None

stripComments: boolean

Configures the handling of HTML comments.

If this option is false, comments will be preserved.

Defaults

true

tagAttributes: Map<string, Set<string>>

The HTML attributes that are allowed on specific tags.

The value is structured as a map from tag names to a set of attribute names.

If a tag is not itself whitelisted, adding entries to this map will do nothing.

Defaults

a =>
    href, hreflang
bdo =>
    dir
blockquote =>
    cite
col =>
    align, char, charoff, span
colgroup =>
    align, char, charoff, span
del =>
    cite, datetime
hr =>
    align, size, width
img =>
    align, alt, height, src, width
ins =>
    cite, datetime
ol =>
    start
q =>
    cite
table =>
    align, char, charoff, summary
tbody =>
    align, char, charoff
td =>
    align, char, charoff, colspan, headers, rowspan
tfoot =>
    align, char, charoff
th =>
    align, char, charoff, colspan, headers, rowspan, scope
thead =>
    align, char, charoff
tr =>
    align, char, charoff
tagAttributeValues: Map<string, Map<string, Set<string>>>

Sets the values of HTML attributes that are allowed on specific tags.

The value is structured as a map from tag names to a map from attribute names to a set of attribute values.

If a tag is not itself whitelisted, adding entries to this map will do nothing.

Defaults

None

tags: Set<string>

The tags that are allowed.

Defaults

a, abbr, acronym, area, article, aside, b, bdi,
bdo, blockquote, br, caption, center, cite, code,
col, colgroup, data, dd, del, details, dfn, div,
dl, dt, em, figcaption, figure, footer, h1, h2,
h3, h4, h5, h6, header, hgroup, hr, i, img,
ins, kbd, kbd, li, map, mark, nav, ol, p, pre,
q, rp, rt, rtc, ruby, s, samp, small, span,
strike, strong, sub, summary, sup, table, tbody,
td, th, thead, time, tr, tt, u, ul, var, wbr
urlSchemes: Set<string>

Sets the URL schemes permitted on href and src attributes.

Defaults

bitcoin, ftp, ftps, geo, http, https, im, irc,
ircs, magnet, mailto, mms, mx, news, nntp,
openpgp4fpr, sip, sms, smsto, ssh, tel, url,
webcal, wtai, xmpp

Methods

Build an Ammonia instance from this builder once all configuration is done.

Once an Ammonia has been built, changes in the builder won't be reflected on the instance anymore.