mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
no issue - ~10x speedup in processing time taken on each keypress when there are many images/image upload components in the editor - edit DOM in memory before changing it in the page to avoid double-render - keep upload components around and re-assign them on re-render, adding or removing an image will still re-generate everything - adds a throttle to the preview rendering so that renders don't get queued up - fixes occasional bug where uploading an image didn't update the markdown correctly due to a timing issue
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
/* global Showdown, html_sanitize*/
|
|
import Ember from 'ember';
|
|
import cajaSanitizers from 'ghost/utils/caja-sanitizers';
|
|
|
|
const {Helper} = Ember;
|
|
|
|
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 Ember.String.htmlSafe(escapedhtml);
|
|
}
|
|
|
|
export default Helper.helper(formatMarkdown);
|