-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrom-markdown.js
83 lines (74 loc) · 1.68 KB
/
from-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict'
exports.enter = {
mathFlow: enterMathFlow,
mathFlowFenceMeta: enterMathFlowMeta,
mathText: enterMathText
}
exports.exit = {
mathFlow: exitMathFlow,
mathFlowFence: exitMathFlowFence,
mathFlowFenceMeta: exitMathFlowMeta,
mathFlowValue: exitMathData,
mathText: exitMathText,
mathTextData: exitMathData
}
function enterMathFlow(token) {
this.enter(
{
type: 'math',
meta: null,
value: '',
data: {
hName: 'div',
hProperties: {className: ['math', 'math-display']},
hChildren: [{type: 'text', value: ''}]
}
},
token
)
}
function enterMathFlowMeta() {
this.buffer()
}
function exitMathFlowMeta() {
var data = this.resume()
this.stack[this.stack.length - 1].meta = data
}
function exitMathFlowFence() {
// Exit if this is the closing fence.
if (this.getData('mathFlowInside')) return
this.buffer()
this.setData('mathFlowInside', true)
}
function exitMathFlow(token) {
var data = this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
var node = this.exit(token)
node.value = data
node.data.hChildren[0].value = data
this.setData('mathFlowInside')
}
function enterMathText(token) {
this.enter(
{
type: 'inlineMath',
value: '',
data: {
hName: 'span',
hProperties: {className: ['math', 'math-inline']},
hChildren: [{type: 'text', value: ''}]
}
},
token
)
this.buffer()
}
function exitMathText(token) {
var data = this.resume()
var node = this.exit(token)
node.value = data
node.data.hChildren[0].value = data
}
function exitMathData(token) {
this.config.enter.data.call(this, token)
this.config.exit.data.call(this, token)
}