mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add example for markdownlint-rule-helpers.applyFixes to documentation (fixes #663).
This commit is contained in:
parent
09911b24cf
commit
2c38ae90fc
3 changed files with 24 additions and 1 deletions
|
@ -928,6 +928,14 @@ bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be
|
||||||
|
|
||||||
<!-- markdownlint-restore -->
|
<!-- markdownlint-restore -->
|
||||||
|
|
||||||
|
### Fixing
|
||||||
|
|
||||||
|
Rules that can be fixed automatically include a `fixInfo` property which is
|
||||||
|
outlined in the [documentation for custom rules](doc/CustomRules.md#authoring).
|
||||||
|
To apply those fixes more easily, the `applyFixes` method in
|
||||||
|
[markdownlint-rule-helpers](helpers/README.md#applying-recommended-fixes) may
|
||||||
|
be used.
|
||||||
|
|
||||||
## Browser
|
## Browser
|
||||||
|
|
||||||
`markdownlint` also works in the browser.
|
`markdownlint` also works in the browser.
|
||||||
|
|
|
@ -17,7 +17,9 @@ change from release to release. There are brief descriptive comments above each
|
||||||
function, but no [JSDoc][jsdoc] annotations. That said, some of what's here will
|
function, but no [JSDoc][jsdoc] annotations. That said, some of what's here will
|
||||||
be useful to custom rule authors and may avoid duplicating code.
|
be useful to custom rule authors and may avoid duplicating code.
|
||||||
|
|
||||||
## Example
|
## Examples
|
||||||
|
|
||||||
|
### Using Helpers from a Custom Rule
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
||||||
|
@ -41,6 +43,18 @@ module.exports = {
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Applying Recommended Fixes
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { "sync": markdownlintSync } = require("markdownlint");
|
||||||
|
const markdownlintRuleHelpers = require("markdownlint-rule-helpers");
|
||||||
|
|
||||||
|
function fixMarkdownlintViolations(content) {
|
||||||
|
const fixResults = markdownlintSync({ strings: { content } });
|
||||||
|
return markdownlintRuleHelpers.applyFixes(content, fixResults.content);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
See also: [`markdownlint` built-in rule implementations][lib].
|
See also: [`markdownlint` built-in rule implementations][lib].
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
|
@ -679,6 +679,7 @@ test("readmeHeadings", (t) => new Promise((resolve) => {
|
||||||
"#### callback",
|
"#### callback",
|
||||||
"#### result",
|
"#### result",
|
||||||
"## Usage",
|
"## Usage",
|
||||||
|
"### Fixing",
|
||||||
"## Browser",
|
"## Browser",
|
||||||
"## Examples",
|
"## Examples",
|
||||||
"## Contributing",
|
"## Contributing",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue