1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

highlight code block for chart.js

This commit is contained in:
Baptiste Augrain
2018-09-14 00:03:33 +02:00
parent 10ffa35b29
commit 4b0dc08426
5 changed files with 118 additions and 3 deletions

View File

@@ -250,7 +250,7 @@ class MarkdownEditor extends React.Component {
: 'codeEditor--hide'
}
ref='code'
mode='GitHub Flavored Markdown'
mode='Boost Flavored Markdown'
value={value}
theme={config.editor.theme}
keyMap={config.editor.keyMap}

View File

@@ -145,7 +145,7 @@ class MarkdownSplitEditor extends React.Component {
styleName='codeEditor'
ref='code'
width={this.state.codeEditorWidthInPercent + '%'}
mode='GitHub Flavored Markdown'
mode='Boost Flavored Markdown'
value={value}
theme={config.editor.theme}
keyMap={config.editor.keyMap}

View File

@@ -1,6 +1,8 @@
'use strict'
module.exports = function (md, renderers, defaultRenderer) {
const paramsRE = /^[ \t]*([\w+#-]+)?(?:\(((?:\s*\w[-\w]*(?:=(?:'(?:.*?[^\\])?'|"(?:.*?[^\\])?"|(?:[^'"][^\s]*)))?)*)\))?(?::([^:]*)(?::(\d+))?)?\s*$/
function fence (state, startLine, endLine) {
let pos = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]
@@ -66,7 +68,7 @@ module.exports = function (md, renderers, defaultRenderer) {
let fileName = ''
let firstLineNumber = 0
let match = /^(\w[-\w]*)?(?:\(((?:\s*\w[-\w]*(?:=(?:'(?:.*?[^\\])?'|"(?:.*?[^\\])?"|(?:[^'"][^\s]*)))?)*)\))?(?::([^:]*)(?::(\d+))?)?\s*$/.exec(params)
let match = paramsRE.exec(params)
if (match) {
if (match[1]) {
langType = match[1]

107
extra_scripts/codemirror/mode/bfm/bfm.js vendored Normal file
View File

@@ -0,0 +1,107 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../codemirror/lib/codemirror"), require("../codemirror/mode/gfm/gfm"), require("../codemirror/mode/yaml-frontmatter/yaml-frontmatter"))
else if (typeof define == "function" && define.amd) // AMD
define(["../codemirror/lib/codemirror", "../codemirror/mode/gfm/gfm", "../codemirror/mode/yaml-frontmatter/yaml-frontmatter"], mod)
else // Plain browser env
mod(CodeMirror)
})(function(CodeMirror) {
'use strict'
const fencedCodeRE = /^(~~~+|```+)[ \t]*([\w+#-]+)?(?:\(((?:\s*\w[-\w]*(?:=(?:'(?:.*?[^\\])?'|"(?:.*?[^\\])?"|(?:[^'"][^\s]*)))?)*)\))?(?::([^:]*)(?::(\d+))?)?\s*$/
function getMode(name, params, config, cm) {
if (!name) {
return null
}
const parameters = {}
if (params) {
const regex = /(\w[-\w]*)(?:=(?:'(.*?[^\\])?'|"(.*?[^\\])?"|([^'"][^\s]*)))?/g
let match
while ((match = regex.exec(params))) {
parameters[match[1]] = match[2] || match[3] || match[4] || null
}
}
if (name === 'chart') {
name = parameters.hasOwnProperty('yaml') ? 'yaml' : 'json'
}
const found = CodeMirror.findModeByName(name)
if (!found) {
return null
}
if (CodeMirror.modes.hasOwnProperty(found.mode)) {
const mode = CodeMirror.getMode(config, found.mode)
return mode.name === 'null' ? null : mode
} else {
CodeMirror.requireMode(found.mode, () => {
cm.setOption('mode', cm.getOption('mode'))
})
}
}
CodeMirror.defineMode('bfm', function (config, baseConfig) {
var bfmOverlay = {
startState: function() {
return {
fencedEndRE: null
}
},
copyState: function(s) {
return {
localMode: s.localMode,
localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
fencedEndRE: s.fencedEndRE
}
},
token: function(stream, state) {
state.combineTokens = false
if (state.fencedEndRE && stream.match(state.fencedEndRE)) {
state.fencedEndRE = null
state.localMode = null
state.localState = null
return null
}
if (state.localMode) {
return state.localMode.token(stream, state.localState) || ''
}
const match = stream.match(fencedCodeRE, true)
if (match) {
state.fencedEndRE = new RegExp(match[1] + '+ *$')
state.localMode = getMode(match[2], match[3], config, stream.lineOracle.doc.cm)
if (state.localMode) {
state.localState = CodeMirror.startState(state.localMode)
}
return null
}
state.combineTokens = true
stream.next()
return null
},
}
baseConfig.name = 'yaml-frontmatter'
return CodeMirror.overlayMode(CodeMirror.getMode(config, baseConfig), bfmOverlay)
}, 'yaml-frontmatter')
CodeMirror.defineMIME('text/x-bfm', 'bfm')
CodeMirror.modeInfo.push({
name: "Boost Flavored Markdown",
mime: "text/x-bfm",
mode: "bfm"
})
})

View File

@@ -93,8 +93,14 @@
<script src="../node_modules/codemirror/keymap/vim.js"></script>
<script src="../node_modules/codemirror/keymap/emacs.js"></script>
<script src="../node_modules/codemirror/addon/runmode/runmode.js"></script>
<script src="../node_modules/codemirror/mode/xml/xml.js"></script>
<script src="../node_modules/codemirror/mode/markdown/markdown.js"></script>
<script src="../node_modules/codemirror/mode/gfm/gfm.js"></script>
<script src="../node_modules/codemirror/mode/yaml/yaml.js"></script>
<script src="../node_modules/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js"></script>
<script src="../extra_scripts/boost/boostNewLineIndentContinueMarkdownList.js"></script>
<script src="../extra_scripts/codemirror/mode/bfm/bfm.js"></script>
<script src="../node_modules/codemirror/addon/edit/closebrackets.js"></script>
<script src="../node_modules/codemirror/addon/edit/matchbrackets.js"></script>