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