Skip to content

Commit cf6cc38

Browse files
committed
[yaml-frontmatter mode] Treat the start of the document as being in the base mode
For purposes of indentation and such. Issue #6737
1 parent 1354f82 commit cf6cc38

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

mode/yaml-frontmatter/yaml-frontmatter.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,55 @@
1717
var yamlMode = CodeMirror.getMode(config, "yaml")
1818
var innerMode = CodeMirror.getMode(config, parserConfig && parserConfig.base || "gfm")
1919

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}
2222
}
2323

2424
return {
2525
startState: function () {
2626
return {
2727
state: START,
28-
inner: CodeMirror.startState(yamlMode)
28+
yaml: null,
29+
inner: CodeMirror.startState(innerMode)
2930
}
3031
},
3132
copyState: function (state) {
3233
return {
3334
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)
3537
}
3638
},
3739
token: function (stream, state) {
3840
if (state.state == START) {
3941
if (stream.match('---', false)) {
4042
state.state = FRONTMATTER
41-
return yamlMode.token(stream, state.inner)
43+
state.yaml = CodeMirror.startState(yamlMode)
44+
return yamlMode.token(stream, state.yaml)
4245
} else {
4346
state.state = BODY
44-
state.inner = CodeMirror.startState(innerMode)
4547
return innerMode.token(stream, state.inner)
4648
}
4749
} else if (state.state == FRONTMATTER) {
4850
var end = stream.sol() && stream.match(/(---|\.\.\.)/, false)
49-
var style = yamlMode.token(stream, state.inner)
51+
var style = yamlMode.token(stream, state.yaml)
5052
if (end) {
5153
state.state = BODY
52-
state.inner = CodeMirror.startState(innerMode)
54+
state.yaml = null
5355
}
5456
return style
5557
} else {
5658
return innerMode.token(stream, state.inner)
5759
}
5860
},
59-
innerMode: function (state) {
60-
return {mode: curMode(state), state: state.inner}
61-
},
61+
innerMode: localMode,
6262
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
6565
},
6666
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)
6969
}
7070
}
7171
})

0 commit comments

Comments
 (0)