[GH-ISSUE #663] Document Node API for auto-fixing markdownlint violations #495

Closed
opened 2026-03-03 01:27:24 +03:00 by kerem · 0 comments
Owner

Originally created by @bmish on GitHub (Dec 3, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/663

I need to fix the markdownlint violations in a string via markdownlint's Node API. I had trouble figuring out how to do this as it doesn't seem to be mentioned in markdownlint's documentation. By looking at various repositories using markdownlint's Node API, I was able to come up with this working example:

const { sync } = require('markdownlint');
const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
const markdownlintConfig = require('./.markdownlint.json');

function fixMarkdownlintViolations(content) {
  const fixResults = sync({
    strings: { content },
    config: markdownlintConfig,
    resultVersion: 3,
  });
  const fixes = fixResults.content.filter((error) => error.fixInfo);
  if (fixes.length > 0) {
    return markdownlintRuleHelpers.applyFixes(content, fixes);
  }
  return content;
}

I guess this is undocumented because of this notice in markdownlint-rule-helpers?

Undocumented - This package exports the internal functions as-is. The APIs were not originally meant to be public, are not officially supported, and may change from release to release. There are brief descriptive comments above each function, but no JSDoc annotations. That said, some of what's here will be useful to custom rule authors and may avoid duplicating code.

Would it make sense to document my example in the markdownlint-rule-helpers README (which has the disclaimer about it being subject to change), perhaps linking to it from the main markdownlint README? I opened a PR to do that in #664. If there's some better place/way to document it, let me know.

Originally created by @bmish on GitHub (Dec 3, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/663 I need to fix the markdownlint violations in a string via markdownlint's Node API. I had trouble figuring out how to do this as it doesn't seem to be mentioned in markdownlint's documentation. By looking at various repositories using markdownlint's Node API, I was able to come up with this working example: ```js const { sync } = require('markdownlint'); const markdownlintRuleHelpers = require('markdownlint-rule-helpers'); const markdownlintConfig = require('./.markdownlint.json'); function fixMarkdownlintViolations(content) { const fixResults = sync({ strings: { content }, config: markdownlintConfig, resultVersion: 3, }); const fixes = fixResults.content.filter((error) => error.fixInfo); if (fixes.length > 0) { return markdownlintRuleHelpers.applyFixes(content, fixes); } return content; } ``` I guess this is undocumented because of this notice in [markdownlint-rule-helpers](https://www.npmjs.com/package/markdownlint-rule-helpers)? > Undocumented - This package exports the internal functions as-is. The APIs were not originally meant to be public, are not officially supported, and may change from release to release. There are brief descriptive comments above each function, but no [JSDoc](https://en.m.wikipedia.org/wiki/JSDoc) annotations. That said, some of what's here will be useful to custom rule authors and may avoid duplicating code. Would it make sense to document my example in the markdownlint-rule-helpers README (which has the disclaimer about it being subject to change), perhaps linking to it from the main markdownlint README? I opened a PR to do that in #664. If there's some better place/way to document it, let me know.
kerem 2026-03-03 01:27:24 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#495
No description provided.