markdownlint/example/standalone.mjs
David Anson 616c3f2c22
Some checks failed
Checkers / linkcheck (push) Has been cancelled
Checkers / spellcheck (push) Has been cancelled
CI / build (20, macos-latest) (push) Has been cancelled
CI / build (20, ubuntu-latest) (push) Has been cancelled
CI / build (20, windows-latest) (push) Has been cancelled
CI / build (22, macos-latest) (push) Has been cancelled
CI / build (22, ubuntu-latest) (push) Has been cancelled
CI / build (22, windows-latest) (push) Has been cancelled
CI / build (24, macos-latest) (push) Has been cancelled
CI / build (24, ubuntu-latest) (push) Has been cancelled
CI / build (24, windows-latest) (push) Has been cancelled
CI / pnpm (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
TestRepos / build (latest, ubuntu-latest) (push) Has been cancelled
UpdateTestRepos / update (push) Has been cancelled
Deprecate LintResults.toString() (at edit time; continue to support at run time), provide helper function formatLintResults, remove outdated grunt/gulp samples, improve typing.
2025-09-08 21:13:50 -07:00

54 lines
1.3 KiB
JavaScript

// @ts-check
import { applyFixes, getVersion } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
// Displays the library version
console.log(getVersion());
const options = {
"files": [ "good.md", "bad.md" ],
"strings": {
"good.string": "# good.string\n\nThis string passes all rules.\n",
"bad.string": "#bad.string\n\n#This string fails\tsome rules.\n"
}
};
if (true) {
// Makes a synchronous call
const results = lintSync(options);
console.dir(results, { "colors": true, "depth": null });
}
if (true) {
// Makes an asynchronous call
lintAsync(options, function callback(error, results) {
if (!error && results) {
console.dir(results, { "colors": true, "depth": null });
}
});
}
if (true) {
// Makes a Promise-based asynchronous call
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);
}