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) {
mod(CodeMirror);
})(function(CodeMirror) {
function validator(text, options) {
function validator(text) {
return lint(text).map(error => {
const lineNumber = error.lineNumber - 1
const {
ruleNames,
ruleDescription,
lineNumber: ln,
errorRange
} = error
const lineNumber = ln - 1
let start, end
if (error.errorRange) {
start = error.errorRange[0] - 1
end = error.errorRange[1] - 1
} else {
start = 0
end = -1
let start = 0, end = -1
if (errorRange) {
[start, end] = errorRange.map(r => r - 1)
}
return {
messageHTML: `${error.ruleNames.join('/')}: ${error.ruleDescription}`,
messageHTML: `${ruleNames.join('/')}: ${ruleDescription}`,
severity: 'error',
from: CodeMirror.Pos(lineNumber, start),
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) {
const { content: errors } = markdownlint.sync({