|
| 1 | +'use strict' |
| 2 | + |
| 3 | +exports.enter = { |
| 4 | + mathFlow: enterMathFlow, |
| 5 | + mathFlowFenceMeta: enterMathFlowMeta, |
| 6 | + mathText: enterMathText |
| 7 | +} |
| 8 | +exports.exit = { |
| 9 | + mathFlow: exitMathFlow, |
| 10 | + mathFlowFence: exitMathFlowFence, |
| 11 | + mathFlowFenceMeta: exitMathFlowMeta, |
| 12 | + mathFlowValue: exitMathData, |
| 13 | + mathText: exitMathText, |
| 14 | + mathTextData: exitMathData |
| 15 | +} |
| 16 | + |
| 17 | +function enterMathFlow(token) { |
| 18 | + this.enter( |
| 19 | + { |
| 20 | + type: 'math', |
| 21 | + meta: null, |
| 22 | + value: '', |
| 23 | + data: { |
| 24 | + hName: 'div', |
| 25 | + hProperties: {className: ['math', 'math-display']}, |
| 26 | + hChildren: [{type: 'text', value: ''}] |
| 27 | + } |
| 28 | + }, |
| 29 | + token |
| 30 | + ) |
| 31 | +} |
| 32 | + |
| 33 | +function enterMathFlowMeta() { |
| 34 | + this.buffer() |
| 35 | +} |
| 36 | + |
| 37 | +function exitMathFlowMeta() { |
| 38 | + var data = this.resume() |
| 39 | + this.stack[this.stack.length - 1].meta = data |
| 40 | +} |
| 41 | + |
| 42 | +function exitMathFlowFence() { |
| 43 | + // Exit if this is the closing fence. |
| 44 | + if (this.getData('mathFlowInside')) return |
| 45 | + this.buffer() |
| 46 | + this.setData('mathFlowInside', true) |
| 47 | +} |
| 48 | + |
| 49 | +function exitMathFlow(token) { |
| 50 | + var data = this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '') |
| 51 | + var node = this.exit(token) |
| 52 | + node.value = data |
| 53 | + node.data.hChildren[0].value = data |
| 54 | + this.setData('mathFlowInside') |
| 55 | +} |
| 56 | + |
| 57 | +function enterMathText(token) { |
| 58 | + this.enter( |
| 59 | + { |
| 60 | + type: 'inlineMath', |
| 61 | + value: '', |
| 62 | + data: { |
| 63 | + hName: 'span', |
| 64 | + hProperties: {className: ['math', 'math-inline']}, |
| 65 | + hChildren: [{type: 'text', value: ''}] |
| 66 | + } |
| 67 | + }, |
| 68 | + token |
| 69 | + ) |
| 70 | + this.buffer() |
| 71 | +} |
| 72 | + |
| 73 | +function exitMathText(token) { |
| 74 | + var data = this.resume() |
| 75 | + var node = this.exit(token) |
| 76 | + node.value = data |
| 77 | + node.data.hChildren[0].value = data |
| 78 | +} |
| 79 | + |
| 80 | +function exitMathData(token) { |
| 81 | + this.config.enter.data.call(this, token) |
| 82 | + this.config.exit.data.call(this, token) |
| 83 | +} |
0 commit comments