mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
3d6856614f
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
33 lines
1.1 KiB
JavaScript
33 lines
1.1 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 default Helper.helper(function (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);
|
|
});
|