/* 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;
@@ -273,16 +273,23 @@
     var 
+escaped
 html = '
@@ -292,16 +292,102 @@
  = '';%0A%0A
+    // convert markdown to HTML%0A    escapedhtml = showdown.makeHtml(markdown %7C%7C '');%0A%0A
     // r
@@ -415,35 +415,41 @@
 ame%0A    
-markdown = markdown
+escapedhtml = escapedhtml
 .replace
@@ -584,27 +584,33 @@
     
-markdown = markdown
+escapedhtml = escapedhtml
 .rep
@@ -746,87 +746,8 @@
 );%0A%0A
-    // convert markdown to HTML%0A    html = showdown.makeHtml(markdown %7C%7C '');%0A%0A
     
@@ -767,16 +767,23 @@
 tml%0A    
+escaped
 html = h
@@ -795,16 +795,23 @@
 anitize(
+escaped
 html, ca
@@ -885,16 +885,23 @@
 eString(
+escaped
 html);%0A%7D

Fix embedded code being removed