mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
23 lines
894 B
JavaScript
23 lines
894 B
JavaScript
/* global Showdown, Handlebars, html_sanitize*/
|
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
|
|
|
var showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm']});
|
|
|
|
var formatMarkdown = Ember.Handlebars.makeBoundHelper(function (markdown) {
|
|
var html = '';
|
|
|
|
// replace script and iFrame
|
|
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>');
|
|
|
|
// convert markdown to HTML
|
|
html = showdown.makeHtml(markdown || '');
|
|
|
|
// sanitize html
|
|
html = html_sanitize(html, cajaSanitizers.url, cajaSanitizers.id);
|
|
return new Handlebars.SafeString(html);
|
|
});
|
|
|
|
export default formatMarkdown; |