forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicParser.js
More file actions
executable file
·68 lines (53 loc) · 1.91 KB
/
basicParser.js
File metadata and controls
executable file
·68 lines (53 loc) · 1.91 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const LANG = require('config').lang;
const MarkdownIt = require('markdown-it');
const charTypographyPlugin = require('./plugins/charTypography');
const extendedCodePlugin = require('./plugins/extendedCode');
const outlinedBlocksPlugin = require('./plugins/outlinedBlocks');
const sourceBlocksPlugin = require('./plugins/sourceBlocks');
const imgDescToAttrsPlugin = require('./plugins/imgDescToAttrs');
const markdownErrorPlugin = require('./plugins/markdownError');
const blockTagsPlugin = require('./plugins/blockTags/plugin');
const cutPlugin = require('./plugins/blockTags/cut');
const deflistPlugin = require('markdown-it-deflist');
const getPrismLanguage = require('./getPrismLanguage');
module.exports = class BasicParser {
constructor(options) {
options = options || {};
this.options = options;
this.env = options.env || {};
this.md = new MarkdownIt(Object.assign({
typographer: true,
blockTags: ['cut'].concat(getPrismLanguage.allSupported),
linkHeaderTag: false,
html: false,
quotes: LANG == 'ru' ? '«»„“' : '“”‘’'
}, options));
extendedCodePlugin(this.md);
outlinedBlocksPlugin(this.md);
sourceBlocksPlugin(this.md);
imgDescToAttrsPlugin(this.md);
markdownErrorPlugin(this.md);
blockTagsPlugin(this.md);
cutPlugin(this.md);
charTypographyPlugin(this.md);
deflistPlugin(this.md);
}
parse(text) {
return this.md.parse(text, this.env);
}
parseInline(text) {
return this.md.parseInline(text, this.env);
}
render(text) {
return this.md.renderer.render(this.parse(text), this.md.options, this.env);
}
renderInline(text) {
let tokens = this.parseInline(text);
let result = this.md.renderer.render(tokens, this.md.options, this.env);
return result;
}
renderTokens(tokens) {
return this.md.renderer.render(tokens, this.md.options, this.env);
}
};