2018-08-09 16:59:03 +03:00
|
|
|
/* global html_sanitize */
|
|
|
|
import cajaSanitizers from 'ghost-admin/utils/caja-sanitizers';
|
|
|
|
import {assign} from '@ember/polyfills';
|
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
import {isArray} from '@ember/array';
|
|
|
|
|
|
|
|
export function sanitizeHtml(params, options = {}) {
|
|
|
|
let html = isArray(params) ? params[0] : params;
|
|
|
|
|
|
|
|
options = assign({replaceJS: true}, options);
|
|
|
|
|
|
|
|
// replace script and iFrame
|
|
|
|
if (options.replaceJS) {
|
|
|
|
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
|
|
'<pre class="js-embed-placeholder">Embedded JavaScript</pre>');
|
|
|
|
html = html.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
|
|
'<pre class="iframe-embed-placeholder">Embedded iFrame</pre>');
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanitize html
|
2018-08-15 18:25:02 +03:00
|
|
|
return html_sanitize(html, cajaSanitizers.url, cajaSanitizers.id);
|
2018-08-09 16:59:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default helper(sanitizeHtml);
|