|
17 | 17 | var yamlMode = CodeMirror.getMode(config, "yaml") |
18 | 18 | var innerMode = CodeMirror.getMode(config, parserConfig && parserConfig.base || "gfm") |
19 | 19 |
|
20 | | - function curMode(state) { |
21 | | - return state.state == BODY ? innerMode : yamlMode |
| 20 | + function localMode(state) { |
| 21 | + return state.state == FRONTMATTER ? {mode: yamlMode, state: state.yaml} : {mode: innerMode, state: state.inner} |
22 | 22 | } |
23 | 23 |
|
24 | 24 | return { |
25 | 25 | startState: function () { |
26 | 26 | return { |
27 | 27 | state: START, |
28 | | - inner: CodeMirror.startState(yamlMode) |
| 28 | + yaml: null, |
| 29 | + inner: CodeMirror.startState(innerMode) |
29 | 30 | } |
30 | 31 | }, |
31 | 32 | copyState: function (state) { |
32 | 33 | return { |
33 | 34 | state: state.state, |
34 | | - inner: CodeMirror.copyState(curMode(state), state.inner) |
| 35 | + yaml: state.yaml && CodeMirror.copyState(yamlMode, state.yaml), |
| 36 | + inner: CodeMirror.copyState(innerMode, state.inner) |
35 | 37 | } |
36 | 38 | }, |
37 | 39 | token: function (stream, state) { |
38 | 40 | if (state.state == START) { |
39 | 41 | if (stream.match('---', false)) { |
40 | 42 | state.state = FRONTMATTER |
41 | | - return yamlMode.token(stream, state.inner) |
| 43 | + state.yaml = CodeMirror.startState(yamlMode) |
| 44 | + return yamlMode.token(stream, state.yaml) |
42 | 45 | } else { |
43 | 46 | state.state = BODY |
44 | | - state.inner = CodeMirror.startState(innerMode) |
45 | 47 | return innerMode.token(stream, state.inner) |
46 | 48 | } |
47 | 49 | } else if (state.state == FRONTMATTER) { |
48 | 50 | var end = stream.sol() && stream.match(/(---|\.\.\.)/, false) |
49 | | - var style = yamlMode.token(stream, state.inner) |
| 51 | + var style = yamlMode.token(stream, state.yaml) |
50 | 52 | if (end) { |
51 | 53 | state.state = BODY |
52 | | - state.inner = CodeMirror.startState(innerMode) |
| 54 | + state.yaml = null |
53 | 55 | } |
54 | 56 | return style |
55 | 57 | } else { |
56 | 58 | return innerMode.token(stream, state.inner) |
57 | 59 | } |
58 | 60 | }, |
59 | | - innerMode: function (state) { |
60 | | - return {mode: curMode(state), state: state.inner} |
61 | | - }, |
| 61 | + innerMode: localMode, |
62 | 62 | indent: function(state, a, b) { |
63 | | - var mode = curMode(state) |
64 | | - return mode.indent ? mode.indent(state.inner, a, b) : CodeMirror.Pass |
| 63 | + var m = localMode(state) |
| 64 | + return m.mode.indent ? m.mode.indent(m.state, a, b) : CodeMirror.Pass |
65 | 65 | }, |
66 | 66 | blankLine: function (state) { |
67 | | - var mode = curMode(state) |
68 | | - if (mode.blankLine) return mode.blankLine(state.inner) |
| 67 | + var m = localMode(state) |
| 68 | + if (m.mode.blankLine) return m.mode.blankLine(m.state) |
69 | 69 | } |
70 | 70 | } |
71 | 71 | }) |
|
0 commit comments