Ghost/core/client/app/helpers/gh-format-html.js

27 lines
925 B
JavaScript
Raw Normal View History

/* global html_sanitize*/
import Ember from 'ember';
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
const {Helper} = Ember;
export default Helper.helper(function (params) {
if (!params || !params.length) {
return;
}
let escapedhtml = params[0] || '';
// 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>');
escapedhtml = escapedhtml.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
2014-07-31 20:42:43 +04:00
'<pre class="iframe-embed-placeholder">Embedded iFrame</pre>');
// sanitize HTML
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
escapedhtml = html_sanitize(escapedhtml, cajaSanitizers.url, cajaSanitizers.id);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
return Ember.String.htmlSafe(escapedhtml);
});