mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #2846 from roottool/IntroduceMarkdownLint#864
Introduce markdownlint #864
This commit is contained in:
@@ -25,6 +25,7 @@ import TurndownService from 'turndown'
|
||||
import {languageMaps} from '../lib/CMLanguageList'
|
||||
import snippetManager from '../lib/SnippetManager'
|
||||
import {generateInEditor, tocExistsInEditor} from 'browser/lib/markdown-toc-generator'
|
||||
import markdownlint from 'markdownlint'
|
||||
|
||||
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||
|
||||
@@ -37,6 +38,38 @@ function translateHotkey (hotkey) {
|
||||
return hotkey.replace(/\s*\+\s*/g, '-').replace(/Command/g, 'Cmd').replace(/Control/g, 'Ctrl')
|
||||
}
|
||||
|
||||
const validatorOfMarkdown = (text, updateLinting) => {
|
||||
const lintOptions = {
|
||||
'strings': {
|
||||
'content': text
|
||||
}
|
||||
}
|
||||
|
||||
return markdownlint(lintOptions, (err, result) => {
|
||||
if (!err) {
|
||||
const foundIssues = []
|
||||
result.content.map(item => {
|
||||
let ruleNames = ''
|
||||
item.ruleNames.map((ruleName, index) => {
|
||||
ruleNames += ruleName
|
||||
if (index === item.ruleNames.length - 1) {
|
||||
ruleNames += ': '
|
||||
} else {
|
||||
ruleNames += '/'
|
||||
}
|
||||
})
|
||||
foundIssues.push({
|
||||
from: CodeMirror.Pos(item.lineNumber, 0),
|
||||
to: CodeMirror.Pos(item.lineNumber, 1),
|
||||
message: ruleNames + item.ruleDescription,
|
||||
severity: 'warning'
|
||||
})
|
||||
})
|
||||
updateLinting(foundIssues)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default class CodeEditor extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
@@ -256,6 +289,7 @@ export default class CodeEditor extends React.Component {
|
||||
snippetManager.init()
|
||||
this.updateDefaultKeyMap()
|
||||
|
||||
const checkMarkdownNoteIsOpening = this.props.mode === 'Boost Flavored Markdown'
|
||||
this.value = this.props.value
|
||||
this.editor = CodeMirror(this.refs.root, {
|
||||
rulers: buildCMRulers(rulers, enableRulers),
|
||||
@@ -272,7 +306,11 @@ export default class CodeEditor extends React.Component {
|
||||
inputStyle: 'textarea',
|
||||
dragDrop: false,
|
||||
foldGutter: true,
|
||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
||||
lint: checkMarkdownNoteIsOpening ? {
|
||||
'getAnnotations': validatorOfMarkdown,
|
||||
'async': true
|
||||
} : false,
|
||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
|
||||
autoCloseBrackets: {
|
||||
pairs: this.props.matchingPairs,
|
||||
triples: this.props.matchingTriples,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<link rel="stylesheet" href="../node_modules/codemirror/lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../node_modules/katex/dist/katex.min.css">
|
||||
<link rel="stylesheet" href="../node_modules/codemirror/addon/dialog/dialog.css">
|
||||
<link rel="stylesheet" href="../node_modules/codemirror/addon/lint/lint.css">
|
||||
<link rel="stylesheet" href="../extra_scripts/codemirror/mode/bfm/bfm.css">
|
||||
|
||||
<title>Boostnote</title>
|
||||
@@ -125,6 +126,8 @@
|
||||
<script src="../node_modules/codemirror/addon/dialog/dialog.js"></script>
|
||||
<script src="../node_modules/codemirror/addon/display/rulers.js"></script>
|
||||
|
||||
<script src="../node_modules/codemirror/addon/lint/lint.js"></script>
|
||||
|
||||
<script src="../node_modules/raphael/raphael.min.js"></script>
|
||||
<script src="../node_modules/flowchart.js/release/flowchart.min.js"></script>
|
||||
<script>
|
||||
@@ -154,4 +157,4 @@
|
||||
</style>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -154,6 +154,7 @@
|
||||
"jest-localstorage-mock": "^2.2.0",
|
||||
"jsdom": "^9.4.2",
|
||||
"json-loader": "^0.5.4",
|
||||
"markdownlint": "^0.11.0",
|
||||
"merge-stream": "^1.0.0",
|
||||
"mock-require": "^3.0.1",
|
||||
"nib": "^1.1.0",
|
||||
|
||||
Reference in New Issue
Block a user