/* global Showdown, html_sanitize*/ import Ember from 'ember'; import cajaSanitizers from 'ghost/utils/caja-sanitizers'; const {Helper} = Ember; let showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm', 'footnotes', 'highlight']}); export default Helper.helper(function (params) { if (!params || !params.length) { return; } let markdown = params[0] || ''; let escapedhtml = ''; // convert markdown to HTML escapedhtml = showdown.makeHtml(markdown); // replace script and iFrame escapedhtml = escapedhtml.replace(/)<[^<]*)*<\/script>/gi, '
Embedded JavaScript
'); escapedhtml = escapedhtml.replace(/)<[^<]*)*<\/iframe>/gi, '
Embedded iFrame
'); // sanitize html // jscs:disable requireCamelCaseOrUpperCaseIdentifiers escapedhtml = html_sanitize(escapedhtml, cajaSanitizers.url, cajaSanitizers.id); // jscs:enable requireCamelCaseOrUpperCaseIdentifiers return Ember.String.htmlSafe(escapedhtml); });