From 3a96164c276d2761041bf67575d35db3c54a54b2 Mon Sep 17 00:00:00 2001 From: roottool Date: Tue, 29 Jan 2019 20:42:24 +0900 Subject: [PATCH] display lint result on CodeEditor #864 --- browser/components/CodeEditor.js | 40 +++++++++++++++++++++++++++++++- lib/main.html | 6 ++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 48634993..7068ff02 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -117,6 +117,39 @@ const languageMaps = { elixir: 'Elixir' } +const validator = (text, updateLinting) => { + const markdownlint = require('markdownlint') + 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) @@ -344,7 +377,12 @@ export default class CodeEditor extends React.Component { inputStyle: 'textarea', dragDrop: false, foldGutter: true, - gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], + lint: { + 'getAnnotations': validator, + 'async': true + }, + mode: 'markdown', + gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'], autoCloseBrackets: { pairs: this.props.matchingPairs, triples: this.props.matchingTriples, diff --git a/lib/main.html b/lib/main.html index a1ea3610..bc7504ad 100644 --- a/lib/main.html +++ b/lib/main.html @@ -10,6 +10,7 @@ + Boostnote @@ -125,6 +126,9 @@ + + +