mirror of https://github.com/status-im/codimd.git
Cleanup
Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
This commit is contained in:
parent
31765a9d34
commit
968e042b05
|
@ -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({
|
||||||
|
|
Loading…
Reference in New Issue