mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
remove use of overlayMode to be able to detect YAML mode in chart code block
This commit is contained in:
63
extra_scripts/codemirror/mode/bfm/bfm.js
vendored
63
extra_scripts/codemirror/mode/bfm/bfm.js
vendored
@@ -46,55 +46,80 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
CodeMirror.defineMode('bfm', function (config, baseConfig) {
|
CodeMirror.defineMode('bfm', function (config, baseConfig) {
|
||||||
var bfmOverlay = {
|
baseConfig.name = 'yaml-frontmatter'
|
||||||
|
const baseMode = CodeMirror.getMode(config, baseConfig)
|
||||||
|
|
||||||
|
return {
|
||||||
startState: function() {
|
startState: function() {
|
||||||
return {
|
return {
|
||||||
|
baseState: CodeMirror.startState(baseMode),
|
||||||
|
|
||||||
fencedEndRE: null
|
fencedEndRE: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copyState: function(s) {
|
copyState: function(s) {
|
||||||
return {
|
return {
|
||||||
localMode: s.localMode,
|
baseState: CodeMirror.copyState(baseMode, s.baseState),
|
||||||
localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
|
|
||||||
|
fencedMode: s.fencedMode,
|
||||||
|
fencedState: s.fencedMode ? CodeMirror.copyState(s.fencedMode, s.fencedState) : null,
|
||||||
|
|
||||||
fencedEndRE: s.fencedEndRE
|
fencedEndRE: s.fencedEndRE
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
token: function(stream, state) {
|
token: function(stream, state) {
|
||||||
state.combineTokens = false
|
const initialPos = stream.pos
|
||||||
|
|
||||||
if (state.fencedEndRE && stream.match(state.fencedEndRE)) {
|
if (state.fencedEndRE && stream.match(state.fencedEndRE)) {
|
||||||
state.fencedEndRE = null
|
state.fencedEndRE = null
|
||||||
state.localMode = null
|
state.fencedMode = null
|
||||||
state.localState = null
|
state.fencedState = null
|
||||||
|
|
||||||
return null
|
stream.pos = initialPos
|
||||||
|
return baseMode.token(stream, state.baseState)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.localMode) {
|
if (state.fencedMode) {
|
||||||
return state.localMode.token(stream, state.localState) || ''
|
return state.fencedMode.token(stream, state.fencedState)
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = stream.match(fencedCodeRE, true)
|
const match = stream.match(fencedCodeRE, true)
|
||||||
if (match) {
|
if (match) {
|
||||||
state.fencedEndRE = new RegExp(match[1] + '+ *$')
|
state.fencedEndRE = new RegExp(match[1] + '+ *$')
|
||||||
|
|
||||||
state.localMode = getMode(match[2], match[3], config, stream.lineOracle.doc.cm)
|
state.fencedMode = getMode(match[2], match[3], config, stream.lineOracle.doc.cm)
|
||||||
if (state.localMode) {
|
if (state.fencedMode) {
|
||||||
state.localState = CodeMirror.startState(state.localMode)
|
state.fencedState = CodeMirror.startState(state.fencedMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
stream.pos = initialPos
|
||||||
|
return baseMode.token(stream, state.baseState)
|
||||||
}
|
}
|
||||||
|
|
||||||
state.combineTokens = true
|
return baseMode.token(stream, state.baseState)
|
||||||
stream.next()
|
|
||||||
return null
|
|
||||||
},
|
},
|
||||||
|
electricChars: baseMode.electricChars,
|
||||||
|
innerMode: function(state) {
|
||||||
|
if (state.fencedMode) {
|
||||||
|
return {
|
||||||
|
mode: state.fencedMode,
|
||||||
|
state: state.fencedState
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
mode: baseMode,
|
||||||
|
state: state.baseState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
blankLine: function(state) {
|
||||||
|
if (state.fencedMode) {
|
||||||
|
return state.fencedMode.blankLine && state.fencedMode.blankLine(state.fencedState)
|
||||||
|
} else {
|
||||||
|
return baseMode.blankLine(state.baseState)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
baseConfig.name = 'yaml-frontmatter'
|
|
||||||
return CodeMirror.overlayMode(CodeMirror.getMode(config, baseConfig), bfmOverlay)
|
|
||||||
}, 'yaml-frontmatter')
|
}, 'yaml-frontmatter')
|
||||||
|
|
||||||
CodeMirror.defineMIME('text/x-bfm', 'bfm')
|
CodeMirror.defineMIME('text/x-bfm', 'bfm')
|
||||||
|
|||||||
Reference in New Issue
Block a user