Skip to content

Commit f2912ef

Browse files
committed
As vscode-markdownlint behavior
Signed-off-by: Yukai Huang <[email protected]>
1 parent ad6f82c commit f2912ef

File tree

1 file changed

+37
-29
lines changed
  • public/js/lib/editor/markdown-lint

1 file changed

+37
-29
lines changed

public/js/lib/editor/markdown-lint/index.js

+37-29
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ require('script-loader!markdownlint');
2929
}
3030

3131
return {
32-
messageHTML: `${ruleNames.slice(0, 1)}: ${ruleDescription}`,
32+
messageHTML: `${ruleNames.join('/')}: ${ruleDescription} <small>markdownlint(${ruleNames[0]})</small>`,
3333
severity: 'error',
3434
from: CodeMirror.Pos(lineNumber, start),
3535
to: CodeMirror.Pos(lineNumber, end),
36-
__ruleNames: ruleNames,
37-
__ruleDescription: ruleDescription,
3836
__error: error
3937
}
4038
})
@@ -47,38 +45,48 @@ export const linterOptions = {
4745
fixedTooltip: true,
4846
contextmenu: annotations => {
4947
const singleFixMenus = annotations
50-
.filter(ann => ann.__error.fixInfo)
5148
.map(annotation => {
5249
const error = annotation.__error
53-
return {
54-
content: `Fix ${error.ruleDescription}`,
55-
onClick () {
56-
const doc = window.editor.doc
57-
const fixInfo = normalizeFixInfo(error.fixInfo, error.lineNumber)
58-
const line = fixInfo.lineNumber - 1
59-
const lineContent = doc.getLine(line) || ''
60-
const fixedText = helpers.applyFix(lineContent, fixInfo, '\n')
50+
const ruleNameAlias = error.ruleNames.join('/')
6151

62-
let from = { line, ch: 0 }
63-
let to = { line, ch: lineContent ? lineContent.length : 0 }
52+
if (annotation.__error.fixInfo) {
53+
return {
54+
content: `Click to fix this violoation of ${ruleNameAlias}`,
55+
onClick () {
56+
const doc = window.editor.doc
57+
const fixInfo = normalizeFixInfo(error.fixInfo, error.lineNumber)
58+
const line = fixInfo.lineNumber - 1
59+
const lineContent = doc.getLine(line) || ''
60+
const fixedText = helpers.applyFix(lineContent, fixInfo, '\n')
6461

65-
if (typeof fixedText === 'string') {
66-
doc.replaceRange(fixedText, from, to)
67-
} else {
68-
if (fixInfo.lineNumber === 1) {
69-
if (doc.lineCount() > 1) {
70-
const nextLineStart = doc.indexFromPos({
71-
line: to.line + 1,
72-
ch: 0
73-
})
74-
to = doc.posFromIndex(nextLineStart)
75-
}
62+
let from = { line, ch: 0 }
63+
let to = { line, ch: lineContent ? lineContent.length : 0 }
64+
65+
if (typeof fixedText === 'string') {
66+
doc.replaceRange(fixedText, from, to)
7667
} else {
77-
const previousLineEnd = doc.indexFromPos(from) - 1
78-
from = doc.posFromIndex(previousLineEnd)
79-
}
68+
if (fixInfo.lineNumber === 1) {
69+
if (doc.lineCount() > 1) {
70+
const nextLineStart = doc.indexFromPos({
71+
line: to.line + 1,
72+
ch: 0
73+
})
74+
to = doc.posFromIndex(nextLineStart)
75+
}
76+
} else {
77+
const previousLineEnd = doc.indexFromPos(from) - 1
78+
from = doc.posFromIndex(previousLineEnd)
79+
}
8080

81-
doc.replaceRange('', from, to)
81+
doc.replaceRange('', from, to)
82+
}
83+
}
84+
}
85+
} else {
86+
return {
87+
content: `Click for more information about ${ruleNameAlias}`,
88+
onClick () {
89+
window.open(error.ruleInformation, '_blank')
8290
}
8391
}
8492
}

0 commit comments

Comments
 (0)