aurelia-templating-resources
Version:
A standard set of behaviors, converters and other resources for use with the Aurelia templating library.
33 lines (29 loc) • 961 B
text/typescript
import { valueConverter } from 'aurelia-binding';
import { inject } from 'aurelia-dependency-injection';
import { HTMLSanitizer } from './html-sanitizer';
/**
* Simple html sanitization converter to preserve whitelisted elements and attributes on a bound property containing html.
*/
export class SanitizeHTMLValueConverter {
/**@internal */
sanitizer: HTMLSanitizer;
/**
* Creates an instanse of the value converter.
* @param sanitizer The html sanitizer.
*/
constructor(sanitizer: HTMLSanitizer) {
this.sanitizer = sanitizer;
}
/**
* Process the provided markup that flows to the view.
* @param untrustedMarkup The untrusted markup to be sanitized.
*/
toView(untrustedMarkup) {
if (untrustedMarkup === null || untrustedMarkup === undefined) {
return null;
}
return this.sanitizer.sanitize(untrustedMarkup);
}
}