forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_markdown.js
46 lines (39 loc) · 1.66 KB
/
_markdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// this is a function so that when it's aliased across multiple cards we do not
// end up modifying the object by reference
const getRandom = () => Math.random().toString(36).slice(2, 9);
module.exports = function markdownCardDefinition() {
return {
name: 'markdown',
type: 'dom',
config: {
commentWrapper: true
},
render: function (opts) {
let converters = require('../converters');
let payload = opts.payload;
let version = opts.options && opts.options.version || 2;
// convert markdown to HTML ready for insertion into dom
let html = converters.markdownConverter.render(payload.markdown || '', getRandom());
if (!html) {
return '';
}
/**
* @deprecated Ghost 1.0's markdown-only renderer wrapped cards. Remove in Ghost 3.0
*/
if (version === 1) {
html = `<div class="kg-card-markdown">${html}</div>`;
}
// use the SimpleDOM document to create a raw HTML section.
// avoids parsing/rendering of potentially broken or unsupported HTML
return opts.env.dom.createRawHTMLSection(html);
},
absoluteToRelative(urlUtils, payload, options) {
payload.markdown = payload.markdown && urlUtils.markdownAbsoluteToRelative(payload.markdown, options);
return payload;
},
relativeToAbsolute(urlUtils, payload, options) {
payload.markdown = payload.markdown && urlUtils.markdownRelativeToAbsolute(payload.markdown, options);
return payload;
}
};
};