@@ -312,42 +312,41 @@ alternate formats.
312
312
313
313
### Linting
314
314
315
- Standard asynchronous API:
315
+ Asynchronous API via ` import { lint } from "markdownlint/async" ` :
316
316
317
317
``` javascript
318
318
/**
319
319
* Lint specified Markdown files.
320
320
*
321
- * @param {Options} options Configuration options.
321
+ * @param {Options | null } options Configuration options.
322
322
* @param {LintCallback} callback Callback (err, result) function.
323
323
* @returns {void}
324
324
*/
325
- function markdownlint (options , callback ) { ... }
325
+ function lint (options , callback ) { ... }
326
326
```
327
327
328
- Synchronous API (for build scripts, etc.) :
328
+ Synchronous API via ` import { lint } from "markdownlint/sync" ` :
329
329
330
330
``` javascript
331
331
/**
332
- * Lint specified Markdown files synchronously .
332
+ * Lint specified Markdown files.
333
333
*
334
- * @param {Options} options Configuration options.
334
+ * @param {Options | null } options Configuration options.
335
335
* @returns {LintResults} Results object.
336
336
*/
337
- function markdownlint. sync (options ) { ... }
337
+ function lint (options ) { ... }
338
338
```
339
339
340
- Promise API (in the ` promises ` namespace like Node.js's
341
- [ ` fs ` Promises API] ( https://nodejs.org/api/fs.html#fs_fs_promises_api ) ):
340
+ Promise API via ` import { lint } from "markdownlint/promise" ` :
342
341
343
342
``` javascript
344
343
/**
345
344
* Lint specified Markdown files.
346
345
*
347
- * @param {Options} options Configuration options.
346
+ * @param {Options | null } options Configuration options.
348
347
* @returns {Promise<LintResults>} Results object.
349
348
*/
350
- function markdownlint (options ) { ... }
349
+ function lint (options ) { ... }
351
350
```
352
351
353
352
#### options
@@ -669,7 +668,7 @@ By default, configuration files are parsed as JSON (and named
669
668
` .markdownlint.json ` ). Custom parsers can be provided to handle other formats
670
669
like JSONC, YAML, and TOML.
671
670
672
- Asynchronous API:
671
+ Asynchronous API via ` import { readConfig } from "markdownlint/async" ` :
673
672
674
673
``` javascript
675
674
/**
@@ -684,22 +683,21 @@ Asynchronous API:
684
683
function readConfig (file , parsers , fs , callback ) { ... }
685
684
```
686
685
687
- Synchronous API:
686
+ Synchronous API via ` import { readConfig } from "markdownlint/sync" ` :
688
687
689
688
``` javascript
690
689
/**
691
- * Read specified configuration file synchronously .
690
+ * Read specified configuration file.
692
691
*
693
692
* @param {string} file Configuration file name.
694
693
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
695
694
* @param {Object} [fs] File system implementation.
696
695
* @returns {Configuration} Configuration object.
697
696
*/
698
- function readConfigSync (file , parsers , fs ) { ... }
697
+ function readConfig (file , parsers , fs ) { ... }
699
698
```
700
699
701
- Promise API (in the ` promises ` namespace like Node.js's
702
- [ ` fs ` Promises API] ( https://nodejs.org/api/fs.html#fs_promises_api ) ):
700
+ Promise API via ` import { readConfig } from "markdownlint/promise" ` :
703
701
704
702
``` javascript
705
703
/**
@@ -772,7 +770,8 @@ Configuration object.
772
770
773
771
Rules that can be fixed automatically include a ` fixInfo ` property which is
774
772
outlined in the [ documentation for custom rules] ( doc/CustomRules.md#authoring ) .
775
- To apply fixes consistently, the ` applyFix ` /` applyFixes ` methods may be used:
773
+ To apply fixes consistently, the ` applyFix ` /` applyFixes ` methods may be used via
774
+ ` import { applyFix, applyFixes } from "markdownlint" ` :
776
775
777
776
``` javascript
778
777
/**
@@ -798,18 +797,19 @@ function applyFixes(input, errors) { ... }
798
797
Invoking ` applyFixes ` with the results of a call to lint can be done like so:
799
798
800
799
``` javascript
801
- import markdownlint from " markdownlint" ;
800
+ import { applyFixes } from " markdownlint" ;
801
+ import { lint as lintSync } from " markdownlint/sync" ;
802
802
803
- const fixResults = markdownlint . sync ({ " strings" : { " content" : original } });
804
- const fixed = markdownlint . applyFixes (original, fixResults .content );
803
+ const results = lintSync ({ " strings" : { " content" : original } });
804
+ const fixed = applyFixes (original, results .content );
805
805
```
806
806
807
807
## Usage
808
808
809
- Invoke ` markdownlint ` and use the ` result ` object's ` toString ` method:
809
+ Invoke ` lint ` and use the ` result ` object's ` toString ` method:
810
810
811
811
``` javascript
812
- import markdownlint from " markdownlint" ;
812
+ import { lint as lintAsync } from " markdownlint/async " ;
813
813
814
814
const options = {
815
815
" files" : [ " good.md" , " bad.md" ],
@@ -819,9 +819,9 @@ const options = {
819
819
}
820
820
};
821
821
822
- markdownlint (options, function callback (err , result ) {
823
- if (! err ) {
824
- console .log (result .toString ());
822
+ lintAsync (options, function callback (error , results ) {
823
+ if (! error && results ) {
824
+ console .log (results .toString ());
825
825
}
826
826
});
827
827
```
@@ -839,21 +839,22 @@ bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [
839
839
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
840
840
```
841
841
842
- Or invoke ` markdownlint.sync ` for a synchronous call:
842
+ Or as a synchronous call:
843
843
844
844
``` javascript
845
- const result = markdownlint .sync (options);
846
- console .log (result .toString ());
845
+ import { lint as lintSync } from " markdownlint/sync" ;
846
+
847
+ const results = lintSync (options);
848
+ console .log (results .toString ());
847
849
```
848
850
849
- To examine the ` result ` object directly:
851
+ To examine the ` result ` object directly via a ` Promise ` -based call :
850
852
851
853
``` javascript
852
- markdownlint (options, function callback (err , result ) {
853
- if (! err) {
854
- console .dir (result, { " colors" : true , " depth" : null });
855
- }
856
- });
854
+ import { lint as lintPromise } from " markdownlint/promise" ;
855
+
856
+ const results = await lintPromise (options);
857
+ console .dir (results, { " colors" : true , " depth" : null });
857
858
```
858
859
859
860
Output:
@@ -910,7 +911,7 @@ Generate normal and minified scripts with:
910
911
npm run build-demo
911
912
```
912
913
913
- Then reference the ` markdownlint ` script:
914
+ Then reference the ` markdownlint-browser ` script:
914
915
915
916
``` html
916
917
<script src =" demo/markdownlint-browser.min.js" ></script >
@@ -924,7 +925,8 @@ const options = {
924
925
" content" : " Some Markdown to lint."
925
926
}
926
927
};
927
- const results = window .markdownlint .markdownlint .sync (options).toString ();
928
+
929
+ const results = globalThis .markdownlint .lintSync (options).toString ();
928
930
```
929
931
930
932
## Examples
0 commit comments