mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add ability to fix issues with markdownlint demo page, refactor slightly.
This commit is contained in:
parent
e1134f0db9
commit
3f637ba8e5
5 changed files with 44 additions and 30 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
demo/markdown-it.min.js
|
demo/markdown-it.min.js
|
||||||
demo/markdownlint-browser.js
|
demo/markdownlint-browser.js
|
||||||
demo/markdownlint-browser.min.js
|
demo/markdownlint-browser.min.js
|
||||||
|
demo/markdownlint-rule-helpers-browser.js
|
||||||
example/typescript/type-check.js
|
example/typescript/type-check.js
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
||||||
coverage
|
coverage
|
||||||
demo/markdown-it.min.js
|
demo/markdown-it.min.js
|
||||||
demo/markdownlint-browser.min.js
|
demo/markdownlint-browser.min.js
|
||||||
|
demo/markdownlint-rule-helpers-browser.js
|
||||||
lib-es3
|
lib-es3
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
var markdownit = window.markdownit({ "html": true });
|
var markdownit = window.markdownit({ "html": true });
|
||||||
var newLineRe = /\r\n|\r|\n/;
|
var newLineRe = /\r\n|\r|\n/;
|
||||||
var hashPrefix = "%m";
|
var hashPrefix = "%m";
|
||||||
var rulesMd = "https://github.com/DavidAnson/markdownlint" +
|
|
||||||
"/blob/main/doc/Rules.md";
|
|
||||||
|
|
||||||
// Do-nothing function
|
// Do-nothing function
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
@ -55,17 +53,15 @@
|
||||||
"config": {
|
"config": {
|
||||||
"MD013": false
|
"MD013": false
|
||||||
},
|
},
|
||||||
"handleRuleFailures": true
|
"handleRuleFailures": true,
|
||||||
|
"resultVersion": 3
|
||||||
};
|
};
|
||||||
var results = window.markdownlint.sync(options);
|
var results = window.markdownlint.sync(options);
|
||||||
violations.innerHTML = results.content.map(function mapResult(result) {
|
violations.innerHTML = results.content.map(function mapResult(result) {
|
||||||
var ruleName = result.ruleNames[0];
|
var ruleName = result.ruleNames.slice(0, 2).join(" / ");
|
||||||
var ruleRef = rulesMd + "#" + ruleName.toLowerCase() + "---" +
|
return "<em><a href='#line' target='" + result.lineNumber + "'>" +
|
||||||
result.ruleDescription.toLowerCase()
|
result.lineNumber + "</a></em> - <a href='" + result.ruleInformation +
|
||||||
.replace(/ /g, "-")
|
"'>" + ruleName + "</a> " +
|
||||||
.replace(/[()]/g, "");
|
|
||||||
return "<a href='#" + result.lineNumber + "'><em>" + result.lineNumber +
|
|
||||||
"</em></a> - <a href='" + ruleRef + "'>" + ruleName + "</a> " +
|
|
||||||
result.ruleDescription +
|
result.ruleDescription +
|
||||||
(result.errorDetail ?
|
(result.errorDetail ?
|
||||||
" [<span class='detail'>" +
|
" [<span class='detail'>" +
|
||||||
|
|
@ -76,13 +72,12 @@
|
||||||
" [<span class='detail'>Context: \"" +
|
" [<span class='detail'>Context: \"" +
|
||||||
sanitize(result.errorContext) +
|
sanitize(result.errorContext) +
|
||||||
"\"</span>]" :
|
"\"</span>]" :
|
||||||
|
"") +
|
||||||
|
(result.fixInfo ?
|
||||||
|
" [<a href='#fix' target='" +
|
||||||
|
encodeURIComponent(JSON.stringify(result)) +
|
||||||
|
"' class='detail'>Fix</a>]" :
|
||||||
"");
|
"");
|
||||||
// + (result.errorRange ?
|
|
||||||
// " <u style='white-space: pre-wrap'>" +
|
|
||||||
// lines[result.lineNumber - 1].substr(
|
|
||||||
// result.errorRange[0] - 1, result.errorRange[1]) +
|
|
||||||
// "</u>" :
|
|
||||||
// "");
|
|
||||||
}).join("<br/>");
|
}).join("<br/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,16 +122,33 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle violation navigation
|
// Handle violation navigation
|
||||||
function onLineNumberClick(e) {
|
function onViolationClick(e) {
|
||||||
var line = document.getElementById("l" + e.target.textContent);
|
switch (e.target.hash) {
|
||||||
if (line) {
|
case "#fix":
|
||||||
var highlighted = document.getElementsByClassName("highlight");
|
var error = JSON.parse(decodeURIComponent(e.target.target));
|
||||||
Array.prototype.forEach.call(highlighted, function forElement(element) {
|
var errors = [ error ];
|
||||||
element.classList.remove("highlight");
|
var fixed = window.helpers.applyFixes(markdown.value, errors);
|
||||||
});
|
markdown.value = fixed;
|
||||||
line.classList.add("highlight");
|
onMarkdownInput();
|
||||||
line.scrollIntoView();
|
e.preventDefault();
|
||||||
e.preventDefault();
|
break;
|
||||||
|
case "#line":
|
||||||
|
var line = document.getElementById("l" + e.target.target);
|
||||||
|
if (line) {
|
||||||
|
var highlighted = document.getElementsByClassName("highlight");
|
||||||
|
Array.prototype.forEach.call(
|
||||||
|
highlighted,
|
||||||
|
function forElement(element) {
|
||||||
|
element.classList.remove("highlight");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
line.classList.add("highlight");
|
||||||
|
line.scrollIntoView();
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +169,7 @@
|
||||||
document.body.addEventListener("drop", onDrop);
|
document.body.addEventListener("drop", onDrop);
|
||||||
openFile.addEventListener("change", onOpenFileChange);
|
openFile.addEventListener("change", onOpenFileChange);
|
||||||
markdown.addEventListener("input", onMarkdownInput);
|
markdown.addEventListener("input", onMarkdownInput);
|
||||||
violations.addEventListener("click", onLineNumberClick, true);
|
violations.addEventListener("click", onViolationClick, true);
|
||||||
copyLink.addEventListener("click", onCopyLinkClick);
|
copyLink.addEventListener("click", onCopyLinkClick);
|
||||||
|
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
|
|
@ -205,7 +217,7 @@
|
||||||
// Detect legacy browsers
|
// Detect legacy browsers
|
||||||
try {
|
try {
|
||||||
/* eslint-disable-next-line no-new */
|
/* eslint-disable-next-line no-new */
|
||||||
new URL(rulesMd);
|
new URL("https://example.com/");
|
||||||
/* eslint-disable-next-line unicorn/prefer-optional-catch-binding */
|
/* eslint-disable-next-line unicorn/prefer-optional-catch-binding */
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
markdown.value = [
|
markdown.value = [
|
||||||
|
|
|
||||||
|
|
@ -3435,7 +3435,7 @@ module.exports={
|
||||||
"ci": "npm run test-cover && npm run lint && npm run test-declaration",
|
"ci": "npm run test-cover && npm run lint && npm run test-declaration",
|
||||||
"build-config-schema": "node schema/build-config-schema.js",
|
"build-config-schema": "node schema/build-config-schema.js",
|
||||||
"build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration",
|
"build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration",
|
||||||
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && cpy ../helpers/package.json ../lib-es3/helpers && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && cpy ../helpers/package.json ../lib-es3/helpers && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && browserify ../lib-es3/helpers/helpers.js --standalone helpers >> markdownlint-rule-helpers-browser.js && uglifyjs markdownlint-browser.js markdownlint-rule-helpers-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
||||||
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
||||||
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
|
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
|
||||||
"clone-test-repos": "make-dir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet",
|
"clone-test-repos": "make-dir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet",
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
"ci": "npm run test-cover && npm run lint && npm run test-declaration",
|
"ci": "npm run test-cover && npm run lint && npm run test-declaration",
|
||||||
"build-config-schema": "node schema/build-config-schema.js",
|
"build-config-schema": "node schema/build-config-schema.js",
|
||||||
"build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration",
|
"build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration",
|
||||||
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && cpy ../helpers/package.json ../lib-es3/helpers && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && cpy ../helpers/package.json ../lib-es3/helpers && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && browserify ../lib-es3/helpers/helpers.js --standalone helpers >> markdownlint-rule-helpers-browser.js && uglifyjs markdownlint-browser.js markdownlint-rule-helpers-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
||||||
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
||||||
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
|
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
|
||||||
"clone-test-repos": "make-dir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet",
|
"clone-test-repos": "make-dir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue