forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderSimpledown.js
More file actions
executable file
·36 lines (28 loc) · 977 Bytes
/
renderSimpledown.js
File metadata and controls
executable file
·36 lines (28 loc) · 977 Bytes
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
const BodyParser = require('simpledownParser').BodyParser;
const HtmlTransformer = require('simpledownParser').HtmlTransformer;
const config = require('config');
/**
* Simple renderer for a text w/o resources
* @param text
* @param options
* @returns {*}
*/
module.exports = function(text, options) {
options = Object.create(options || {});
if (options.trusted === undefined) {
options.trusted = true;
}
if (options.applyContextTypography === undefined) {
options.applyContextTypography = true;
}
const node = new BodyParser(text, options).parseAndWrap();
const transformer = new HtmlTransformer({
staticHost: config.server.staticHost
});
var result = transformer.transform(node, options.applyContextTypography);
// if typography is not applied, we need to strip local <no-typography> tags which prevent it
if (!options.applyContextTypography) {
result = result.replace(/<\/?no-typography>/g, '');
}
return result;
};