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