Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
This commit is contained in:
Yukai Huang 2019-08-16 23:27:19 +08:00
parent 31765a9d34
commit 968e042b05
No known key found for this signature in database
GPG Key ID: D4D3B2F0E99D4914
1 changed files with 14 additions and 12 deletions

View File

@ -7,21 +7,23 @@ import './lint.css'
(function(mod) { (function(mod) {
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
function validator(text, options) { function validator(text) {
return lint(text).map(error => { return lint(text).map(error => {
const lineNumber = error.lineNumber - 1 const {
ruleNames,
ruleDescription,
lineNumber: ln,
errorRange
} = error
const lineNumber = ln - 1
let start, end let start = 0, end = -1
if (error.errorRange) { if (errorRange) {
start = error.errorRange[0] - 1 [start, end] = errorRange.map(r => r - 1)
end = error.errorRange[1] - 1
} else {
start = 0
end = -1
} }
return { return {
messageHTML: `${error.ruleNames.join('/')}: ${error.ruleDescription}`, messageHTML: `${ruleNames.join('/')}: ${ruleDescription}`,
severity: 'error', severity: 'error',
from: CodeMirror.Pos(lineNumber, start), from: CodeMirror.Pos(lineNumber, start),
to: CodeMirror.Pos(lineNumber, end) to: CodeMirror.Pos(lineNumber, end)
@ -29,8 +31,8 @@ import './lint.css'
}) })
} }
CodeMirror.registerHelper('lint', 'markdown', validator); CodeMirror.registerHelper('lint', 'markdown', validator)
}); })
function lint (content) { function lint (content) {
const { content: errors } = markdownlint.sync({ const { content: errors } = markdownlint.sync({