-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrules.js
62 lines (56 loc) · 1.63 KB
/
rules.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const linebreakRule = {
filter: 'hr',
replacement: function(content, node, options) {
return content + options.hr + '\n<br>';
}
};
const figureDivNoLinkeBreakRule = {
filter: function(node, options) {
return (
node.nodeName === 'DIV' &&
node.parentNode &&
node.parentNode.nodeName === 'FIGURE'
);
},
replacement: function(content, node, options) {
return content.trim();
}
}
const figCaptionEnclosing = {
filter: function(node, options) {
return (
node.nodeName === 'FIGCAPTION' &&
node.parentNode &&
node.parentNode.nodeName === 'FIGURE'
);
},
replacement: function(content, node, options) {
const ret = content.trim();
return '*(' + ret + ')*';
}
}
const codeFormattingRule = {
filter: 'pre',
replacement: function(content, node, options) {
const end = '```\n';
const begin = '```code_language\n';
const linebreak = '\n';
const NODENAME = 'PRE';
if (node.nextSibling && node.nextSibling.nodeName === NODENAME) {
if (node.previousSibling && node.previousSibling.nodeName === NODENAME) {
return content + linebreak;
}
return begin + content + linebreak;
}
if (node.previousSibling && node.previousSibling.nodeName === NODENAME) {
return content + linebreak + end;
}
return begin + content + linebreak + end;
}
}
module.exports = {
linebreakRule,
figureDivNoLinkeBreakRule,
figCaptionEnclosing,
codeFormattingRule,
};