2014-07-25 14:42:42 +04:00
|
|
|
/* global Showdown, Handlebars, html_sanitize*/
|
|
|
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
var showdown,
|
|
|
|
formatMarkdown;
|
2014-03-02 18:30:35 +04:00
|
|
|
|
2014-10-12 09:19:31 +04:00
|
|
|
showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm', 'footnotes']});
|
2014-10-25 01:09:50 +04:00
|
|
|
|
|
|
|
formatMarkdown = Ember.Handlebars.makeBoundHelper(function (markdown) {
|
2014-08-05 16:11:20 +04:00
|
|
|
var escapedhtml = '';
|
|
|
|
|
|
|
|
// convert markdown to HTML
|
|
|
|
escapedhtml = showdown.makeHtml(markdown || '');
|
2014-07-25 14:42:42 +04:00
|
|
|
|
|
|
|
// replace script and iFrame
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:disable
|
2014-08-05 16:11:20 +04:00
|
|
|
escapedhtml = escapedhtml.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
2014-07-31 22:05:56 +04:00
|
|
|
'<pre class="js-embed-placeholder">Embedded JavaScript</pre>');
|
2014-08-05 16:11:20 +04:00
|
|
|
escapedhtml = escapedhtml.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
2014-07-31 22:05:56 +04:00
|
|
|
'<pre class="iframe-embed-placeholder">Embedded iFrame</pre>');
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:enable
|
2014-07-25 14:42:42 +04:00
|
|
|
|
|
|
|
// sanitize html
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
2014-08-05 16:11:20 +04:00
|
|
|
escapedhtml = html_sanitize(escapedhtml, cajaSanitizers.url, cajaSanitizers.id);
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
|
|
|
|
2014-08-05 16:11:20 +04:00
|
|
|
return new Handlebars.SafeString(escapedhtml);
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
export default formatMarkdown;
|