@@ -25,6 +25,7 @@ import TurndownService from 'turndown'
25
25
import { languageMaps } from '../lib/CMLanguageList'
26
26
import snippetManager from '../lib/SnippetManager'
27
27
import { generateInEditor , tocExistsInEditor } from 'browser/lib/markdown-toc-generator'
28
+ import markdownlint from 'markdownlint'
28
29
29
30
CodeMirror . modeURL = '../node_modules/codemirror/mode/%N/%N.js'
30
31
@@ -37,6 +38,38 @@ function translateHotkey (hotkey) {
37
38
return hotkey . replace ( / \s * \+ \s * / g, '-' ) . replace ( / C o m m a n d / g, 'Cmd' ) . replace ( / C o n t r o l / g, 'Ctrl' )
38
39
}
39
40
41
+ const validatorOfMarkdown = ( text , updateLinting ) => {
42
+ const lintOptions = {
43
+ 'strings' : {
44
+ 'content' : text
45
+ }
46
+ }
47
+
48
+ return markdownlint ( lintOptions , ( err , result ) => {
49
+ if ( ! err ) {
50
+ const foundIssues = [ ]
51
+ result . content . map ( item => {
52
+ let ruleNames = ''
53
+ item . ruleNames . map ( ( ruleName , index ) => {
54
+ ruleNames += ruleName
55
+ if ( index === item . ruleNames . length - 1 ) {
56
+ ruleNames += ': '
57
+ } else {
58
+ ruleNames += '/'
59
+ }
60
+ } )
61
+ foundIssues . push ( {
62
+ from : CodeMirror . Pos ( item . lineNumber , 0 ) ,
63
+ to : CodeMirror . Pos ( item . lineNumber , 1 ) ,
64
+ message : ruleNames + item . ruleDescription ,
65
+ severity : 'warning'
66
+ } )
67
+ } )
68
+ updateLinting ( foundIssues )
69
+ }
70
+ } )
71
+ }
72
+
40
73
export default class CodeEditor extends React . Component {
41
74
constructor ( props ) {
42
75
super ( props )
@@ -256,6 +289,7 @@ export default class CodeEditor extends React.Component {
256
289
snippetManager . init ( )
257
290
this . updateDefaultKeyMap ( )
258
291
292
+ const checkMarkdownNoteIsOpening = this . props . mode === 'Boost Flavored Markdown'
259
293
this . value = this . props . value
260
294
this . editor = CodeMirror ( this . refs . root , {
261
295
rulers : buildCMRulers ( rulers , enableRulers ) ,
@@ -272,7 +306,11 @@ export default class CodeEditor extends React.Component {
272
306
inputStyle : 'textarea' ,
273
307
dragDrop : false ,
274
308
foldGutter : true ,
275
- gutters : [ 'CodeMirror-linenumbers' , 'CodeMirror-foldgutter' ] ,
309
+ lint : checkMarkdownNoteIsOpening ? {
310
+ 'getAnnotations' : validatorOfMarkdown ,
311
+ 'async' : true
312
+ } : false ,
313
+ gutters : [ 'CodeMirror-linenumbers' , 'CodeMirror-foldgutter' , 'CodeMirror-lint-markers' ] ,
276
314
autoCloseBrackets : {
277
315
pairs : this . props . matchingPairs ,
278
316
triples : this . props . matchingTriples ,
0 commit comments