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