import Ember from 'ember'; /* global Showdown, html_sanitize*/ import cajaSanitizers from 'ghost/utils/caja-sanitizers'; var showdown, formatMarkdown; showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm', 'footnotes', 'highlight']}); formatMarkdown = Ember.HTMLBars.makeBoundHelper(function (arr /* hashParams */) { if (!arr || !arr.length) { return; } var escapedhtml = '', markdown = arr[0] || ''; // 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); }); export default formatMarkdown;