2019-10-30 20:37:06 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2024-12-04 23:23:56 -08:00
|
|
|
import { applyFixes, getVersion } from "markdownlint";
|
2024-12-03 19:58:28 -08:00
|
|
|
import { lint as lintAsync } from "markdownlint/async";
|
|
|
|
import { lint as lintPromise } from "markdownlint/promise";
|
|
|
|
import { lint as lintSync } from "markdownlint/sync";
|
2015-03-13 18:20:56 -07:00
|
|
|
|
2024-12-04 23:23:56 -08:00
|
|
|
// Displays the library version
|
|
|
|
console.log(getVersion());
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-04-29 18:46:52 -07:00
|
|
|
"files": [ "good.md", "bad.md" ],
|
|
|
|
"strings": {
|
2019-05-06 22:00:38 -07:00
|
|
|
"good.string": "# good.string\n\nThis string passes all rules.\n",
|
|
|
|
"bad.string": "#bad.string\n\n#This string fails\tsome rules.\n"
|
2015-04-29 18:46:52 -07:00
|
|
|
}
|
2015-03-13 18:20:56 -07:00
|
|
|
};
|
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
if (true) {
|
2015-03-13 18:20:56 -07:00
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
// Makes a synchronous call, uses result.toString for pretty formatting
|
|
|
|
const results = lintSync(options);
|
|
|
|
console.log(results.toString());
|
2015-03-20 00:09:55 -07:00
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
|
|
|
// Makes an asynchronous call, uses result.toString for pretty formatting
|
|
|
|
lintAsync(options, function callback(error, results) {
|
|
|
|
if (!error && results) {
|
|
|
|
console.log(results.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
|
|
|
// Makes a Promise-based asynchronous call, displays the result object directly
|
|
|
|
const results = await lintPromise(options);
|
|
|
|
console.dir(results, { "colors": true, "depth": null });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
|
|
|
// Fixes all supported violations in Markdown content
|
|
|
|
const original = "# Heading";
|
|
|
|
const results = lintSync({ "strings": { "content": original } });
|
|
|
|
const fixed = applyFixes(original, results.content);
|
|
|
|
console.log(fixed);
|
2024-11-28 20:36:44 -08:00
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
}
|