Ghost/ghost/admin/lib/ghost-editor/addon/libs/format-markdown.js
Ryan McCarvill e422f0bcba 👷🏻‍♀️🚧👷 Ghost-Editor integration.
Integrated Ghost-Editor as an in-repo addon.
Moved CSS to /app/styles/addons/ghost-editor/

Still a WIP.
2017-03-02 09:56:51 +00:00

34 lines
1.2 KiB
JavaScript

/* global Showdown, html_sanitize*/
import {helper} from 'ember-helper';
import {htmlSafe} from 'ember-string';
import cajaSanitizers from './caja-sanitizers';
let showdown = new Showdown.converter({extensions: ['ghostimagepreview', 'ghostgfm', 'footnotes', 'highlight']});
export function formatMarkdown(params) {
if (!params || !params.length) {
return;
}
let markdown = params[0] || '';
let escapedhtml = '';
// convert markdown to HTML
escapedhtml = showdown.makeHtml(markdown);
// replace script and iFrame
escapedhtml = escapedhtml.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
'<pre class="js-embed-placeholder">Embedded JavaScript</pre>');
escapedhtml = escapedhtml.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
'<pre class="iframe-embed-placeholder">Embedded iFrame</pre>');
// sanitize html
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
escapedhtml = html_sanitize(escapedhtml, cajaSanitizers.url, cajaSanitizers.id);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
return htmlSafe(escapedhtml);
}
export default helper(formatMarkdown);