markdownlint/example/standalone.mjs
David Anson 93a42ae891
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
wip
2025-09-05 17:51:13 -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);
}