2019-10-30 20:37:06 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import markdownlint from "markdownlint";
|
2015-03-13 18:20:56 -07:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-07-05 21:53:21 -07:00
|
|
|
// Makes a synchronous call, using result.toString for pretty formatting
|
2018-04-27 22:05:34 -07:00
|
|
|
const result = markdownlint.sync(options);
|
2017-07-05 21:53:21 -07:00
|
|
|
console.log(result.toString());
|
2015-03-13 18:20:56 -07:00
|
|
|
|
2017-07-05 21:53:21 -07:00
|
|
|
// Makes an asynchronous call
|
2015-03-13 18:20:56 -07:00
|
|
|
markdownlint(options, function callback(err, result) {
|
|
|
|
if (!err) {
|
2024-11-28 20:36:44 -08:00
|
|
|
// @ts-ignore
|
2017-07-05 21:53:21 -07:00
|
|
|
console.log(result.toString());
|
2015-03-13 18:20:56 -07:00
|
|
|
}
|
|
|
|
});
|
2015-03-20 00:09:55 -07:00
|
|
|
|
2017-07-05 21:53:21 -07:00
|
|
|
// Displays the result object directly
|
2016-10-16 21:46:02 -07:00
|
|
|
markdownlint(options, function callback(err, result) {
|
|
|
|
if (!err) {
|
2016-10-31 22:53:46 -07:00
|
|
|
console.dir(result, { "colors": true, "depth": null });
|
2016-10-16 21:46:02 -07:00
|
|
|
}
|
|
|
|
});
|
2024-11-28 20:36:44 -08:00
|
|
|
|
|
|
|
// Fixes all supported violations in Markdown content
|
|
|
|
const original = "# Heading";
|
|
|
|
const fixResults = markdownlint.sync({ "strings": { "content": original } });
|
|
|
|
const fixed = markdownlint.applyFixes(original, fixResults.content);
|
|
|
|
console.log(fixed);
|