UNPKG

961 BPlain TextView Raw
1import { valueConverter } from 'aurelia-binding';
2import { inject } from 'aurelia-dependency-injection';
3import { HTMLSanitizer } from './html-sanitizer';
4
5/**
6 * Simple html sanitization converter to preserve whitelisted elements and attributes on a bound property containing html.
7 */
8@valueConverter('sanitizeHTML')
9@inject(HTMLSanitizer)
10export class SanitizeHTMLValueConverter {
11 /**@internal */
12 sanitizer: HTMLSanitizer;
13 /**
14 * Creates an instanse of the value converter.
15 * @param sanitizer The html sanitizer.
16 */
17 constructor(sanitizer: HTMLSanitizer) {
18 this.sanitizer = sanitizer;
19 }
20
21 /**
22 * Process the provided markup that flows to the view.
23 * @param untrustedMarkup The untrusted markup to be sanitized.
24 */
25 toView(untrustedMarkup) {
26 if (untrustedMarkup === null || untrustedMarkup === undefined) {
27 return null;
28 }
29
30 return this.sanitizer.sanitize(untrustedMarkup);
31 }
32}