2015-02-09 18:57:50 +03:00
|
|
|
/* global html_sanitize*/
|
2015-10-28 14:36:45 +03:00
|
|
|
import Ember from 'ember';
|
2014-07-25 14:42:42 +04:00
|
|
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const {Helper} = Ember;
|
|
|
|
|
|
|
|
export default Helper.helper(function (params) {
|
2015-09-03 14:06:50 +03:00
|
|
|
if (!params || !params.length) {
|
2015-02-09 18:57:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
let escapedhtml = params[0] || '';
|
2014-07-25 14:42:42 +04:00
|
|
|
|
|
|
|
// replace script and iFrame
|
|
|
|
escapedhtml = escapedhtml.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
2014-07-31 20:42:43 +04:00
|
|
|
'<pre class="js-embed-placeholder">Embedded JavaScript</pre>');
|
2014-07-25 14:42:42 +04:00
|
|
|
escapedhtml = escapedhtml.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
2014-07-31 20:42:43 +04:00
|
|
|
'<pre class="iframe-embed-placeholder">Embedded iFrame</pre>');
|
2014-07-25 14:42:42 +04:00
|
|
|
|
|
|
|
// sanitize HTML
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
2014-07-25 14:42:42 +04:00
|
|
|
escapedhtml = html_sanitize(escapedhtml, cajaSanitizers.url, cajaSanitizers.id);
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
|
|
|
|
2015-02-09 18:57:50 +03:00
|
|
|
return Ember.String.htmlSafe(escapedhtml);
|
2014-07-25 14:42:42 +04:00
|
|
|
});
|