markdownlint 0.36.1 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +70 -117
- package/doc/CustomRules.md +6 -6
- package/helpers/README.md +2 -2
- package/helpers/{helpers.js → helpers.cjs} +15 -6
- package/helpers/micromark-helpers.cjs +5 -3
- package/helpers/package.json +2 -5
- package/lib/{cache.js → cache.mjs} +9 -17
- package/lib/configuration-strict.d.ts +104 -104
- package/lib/configuration.d.ts +1 -1
- package/lib/{constants.js → constants.mjs} +4 -6
- package/lib/exports-async.d.mts +1 -0
- package/lib/exports-async.mjs +3 -0
- package/lib/exports-promise.d.mts +1 -0
- package/lib/exports-promise.mjs +3 -0
- package/lib/exports-sync.d.mts +1 -0
- package/lib/exports-sync.mjs +3 -0
- package/lib/exports.d.mts +28 -0
- package/lib/exports.mjs +31 -0
- package/lib/markdownit.cjs +9 -5
- package/lib/{markdownlint.d.ts → markdownlint.d.mts} +66 -76
- package/lib/{markdownlint.js → markdownlint.mjs} +69 -75
- package/lib/{md001.js → md001.mjs} +5 -8
- package/lib/{md003.js → md003.mjs} +5 -8
- package/lib/{md004.js → md004.mjs} +6 -9
- package/lib/{md005.js → md005.mjs} +4 -7
- package/lib/{md007.js → md007.mjs} +8 -13
- package/lib/{md009.js → md009.mjs} +5 -8
- package/lib/{md010.js → md010.mjs} +7 -11
- package/lib/{md011.js → md011.mjs} +7 -11
- package/lib/{md012.js → md012.mjs} +5 -8
- package/lib/{md013.js → md013.mjs} +8 -9
- package/lib/{md014.js → md014.mjs} +4 -7
- package/lib/{md018.js → md018.mjs} +5 -8
- package/lib/{md019-md021.js → md019-md021.mjs} +7 -10
- package/lib/{md020.js → md020.mjs} +5 -8
- package/lib/{md022.js → md022.mjs} +5 -8
- package/lib/{md023.js → md023.mjs} +4 -7
- package/lib/{md024.js → md024.mjs} +5 -8
- package/lib/{md025.js → md025.mjs} +5 -8
- package/lib/{md026.js → md026.mjs} +5 -8
- package/lib/{md027.js → md027.mjs} +12 -9
- package/lib/{md028.js → md028.mjs} +4 -7
- package/lib/{md029.js → md029.mjs} +6 -9
- package/lib/{md030.js → md030.mjs} +4 -7
- package/lib/{md031.js → md031.mjs} +7 -10
- package/lib/{md032.js → md032.mjs} +5 -8
- package/lib/{md033.js → md033.mjs} +5 -8
- package/lib/{md034.js → md034.mjs} +5 -6
- package/lib/{md035.js → md035.mjs} +4 -7
- package/lib/{md036.js → md036.mjs} +6 -9
- package/lib/{md037.js → md037.mjs} +4 -7
- package/lib/{md038.js → md038.mjs} +5 -8
- package/lib/{md039.js → md039.mjs} +9 -12
- package/lib/{md040.js → md040.mjs} +5 -8
- package/lib/{md041.js → md041.mjs} +4 -8
- package/lib/{md042.js → md042.mjs} +5 -8
- package/lib/{md043.js → md043.mjs} +5 -8
- package/lib/{md044.js → md044.mjs} +8 -11
- package/lib/{md045.js → md045.mjs} +5 -8
- package/lib/{md046.js → md046.mjs} +4 -7
- package/lib/{md047.js → md047.mjs} +3 -6
- package/lib/{md048.js → md048.mjs} +5 -8
- package/lib/{md049-md050.js → md049-md050.mjs} +8 -11
- package/lib/{md051.js → md051.mjs} +8 -12
- package/lib/{md052.js → md052.mjs} +4 -7
- package/lib/{md053.js → md053.mjs} +4 -7
- package/lib/{md054.js → md054.mjs} +5 -8
- package/lib/{md055.js → md055.mjs} +6 -7
- package/lib/{md056.js → md056.mjs} +7 -8
- package/lib/{md058.js → md058.mjs} +6 -7
- package/{helpers/micromark-parse.cjs → lib/micromark-parse.mjs} +29 -33
- package/lib/micromark-types.d.mts +11 -0
- package/lib/rules.mjs +118 -0
- package/lib/types.d.mts +12 -0
- package/package.json +36 -32
- package/schema/.markdownlint.jsonc +51 -51
- package/schema/.markdownlint.yaml +51 -51
- package/schema/markdownlint-config-schema-strict.json +106 -106
- package/schema/markdownlint-config-schema.json +106 -106
- package/demo/markdownlint-browser.js +0 -7138
- package/helpers/test.cjs +0 -28
- package/lib/rules.js +0 -74
- /package/helpers/{shared.js → shared.cjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.37.0
|
|
4
|
+
|
|
5
|
+
- Convert module to ECMAScript (breaking change)
|
|
6
|
+
- <https://nodejs.org/docs/latest/api/esm.html>
|
|
7
|
+
- <https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c>
|
|
8
|
+
- Convert module to named exports (breaking change)
|
|
9
|
+
|
|
3
10
|
## 0.36.1
|
|
4
11
|
|
|
5
12
|
- Fix behavior of MD054
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ as well as directives, footnotes, and math syntax - all implemented by
|
|
|
75
75
|
[markdownlint-problem-matcher]: https://github.com/xt0rted/markdownlint-problem-matcher
|
|
76
76
|
[nodejs-extensions]: https://github.com/Lombiq/NodeJs-Extensions
|
|
77
77
|
[rubygems-mdl]: https://rubygems.org/gems/mdl
|
|
78
|
-
[sublimelinter]: https://
|
|
78
|
+
[sublimelinter]: https://github.com/jonlabelle/SublimeLinter-contrib-markdownlint
|
|
79
79
|
[super-linter]: https://github.com/super-linter/super-linter
|
|
80
80
|
[vscode-markdownlint]: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
|
|
81
81
|
|
|
@@ -312,42 +312,41 @@ alternate formats.
|
|
|
312
312
|
|
|
313
313
|
### Linting
|
|
314
314
|
|
|
315
|
-
|
|
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
|
|
325
|
+
function lint(options, callback) { ... }
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
-
Synchronous API
|
|
328
|
+
Synchronous API via `import { lint } from "markdownlint/sync"`:
|
|
329
329
|
|
|
330
330
|
```javascript
|
|
331
331
|
/**
|
|
332
|
-
* Lint specified Markdown files
|
|
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
|
|
337
|
+
function lint(options) { ... }
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
-
Promise API
|
|
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
|
|
349
|
+
function lint(options) { ... }
|
|
351
350
|
```
|
|
352
351
|
|
|
353
352
|
#### options
|
|
@@ -547,7 +546,7 @@ Type: `Object` implementing the [file system API][node-fs-api]
|
|
|
547
546
|
|
|
548
547
|
In advanced scenarios, it may be desirable to bypass the default file system
|
|
549
548
|
API. If a custom file system implementation is provided, `markdownlint` will use
|
|
550
|
-
that instead of
|
|
549
|
+
that instead of using `node:fs`.
|
|
551
550
|
|
|
552
551
|
Note: The only methods called are `readFile` and `readFileSync`.
|
|
553
552
|
|
|
@@ -669,14 +668,14 @@ 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
|
/**
|
|
676
675
|
* Read specified configuration file.
|
|
677
676
|
*
|
|
678
677
|
* @param {string} file Configuration file name.
|
|
679
|
-
* @param {ConfigurationParser[] | ReadConfigCallback} parsers Parsing function.
|
|
678
|
+
* @param {ConfigurationParser[] | ReadConfigCallback} [parsers] Parsing function(s).
|
|
680
679
|
* @param {Object} [fs] File system implementation.
|
|
681
680
|
* @param {ReadConfigCallback} [callback] Callback (err, result) function.
|
|
682
681
|
* @returns {void}
|
|
@@ -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
|
|
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
|
|
697
|
+
function readConfig(file, parsers, fs) { ... }
|
|
699
698
|
```
|
|
700
699
|
|
|
701
|
-
Promise API
|
|
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
|
/**
|
|
@@ -751,7 +749,7 @@ Type: *Optional* `Object` implementing the [file system API][file-system-api]
|
|
|
751
749
|
|
|
752
750
|
In advanced scenarios, it may be desirable to bypass the default file system
|
|
753
751
|
API. If a custom file system implementation is provided, `markdownlint` will use
|
|
754
|
-
that instead of invoking `
|
|
752
|
+
that instead of invoking `node:fs`.
|
|
755
753
|
|
|
756
754
|
Note: The only methods called are `readFile`, `readFileSync`, `access`, and
|
|
757
755
|
`accessSync`.
|
|
@@ -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,20 +797,44 @@ 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
|
-
|
|
800
|
+
import { applyFixes } from "markdownlint";
|
|
801
|
+
import { lint as lintSync } from "markdownlint/sync";
|
|
802
802
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
return applyFixes(content, fixResults.content);
|
|
806
|
-
}
|
|
803
|
+
const results = lintSync({ "strings": { "content": original } });
|
|
804
|
+
const fixed = applyFixes(original, results.content);
|
|
807
805
|
```
|
|
808
806
|
|
|
807
|
+
### Miscellaneous
|
|
808
|
+
|
|
809
|
+
To get the [semantic version][semver] of the library, the `getVersion` method
|
|
810
|
+
can be used:
|
|
811
|
+
|
|
812
|
+
```javascript
|
|
813
|
+
/**
|
|
814
|
+
* Gets the (semantic) version of the library.
|
|
815
|
+
*
|
|
816
|
+
* @returns {string} SemVer string.
|
|
817
|
+
*/
|
|
818
|
+
function getVersion() { ... }
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
Invoking `getVersion` is simple:
|
|
822
|
+
|
|
823
|
+
```javascript
|
|
824
|
+
import { getVersion } from "markdownlint";
|
|
825
|
+
|
|
826
|
+
// Displays the library version
|
|
827
|
+
console.log(getVersion());
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
[semver]: https://semver.org
|
|
831
|
+
|
|
809
832
|
## Usage
|
|
810
833
|
|
|
811
|
-
Invoke `
|
|
834
|
+
Invoke `lint` and use the `result` object's `toString` method:
|
|
812
835
|
|
|
813
836
|
```javascript
|
|
814
|
-
|
|
837
|
+
import { lint as lintAsync } from "markdownlint/async";
|
|
815
838
|
|
|
816
839
|
const options = {
|
|
817
840
|
"files": [ "good.md", "bad.md" ],
|
|
@@ -821,9 +844,9 @@ const options = {
|
|
|
821
844
|
}
|
|
822
845
|
};
|
|
823
846
|
|
|
824
|
-
|
|
825
|
-
if (!
|
|
826
|
-
console.log(
|
|
847
|
+
lintAsync(options, function callback(error, results) {
|
|
848
|
+
if (!error && results) {
|
|
849
|
+
console.log(results.toString());
|
|
827
850
|
}
|
|
828
851
|
});
|
|
829
852
|
```
|
|
@@ -841,21 +864,22 @@ bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [
|
|
|
841
864
|
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
|
|
842
865
|
```
|
|
843
866
|
|
|
844
|
-
Or
|
|
867
|
+
Or as a synchronous call:
|
|
845
868
|
|
|
846
869
|
```javascript
|
|
847
|
-
|
|
848
|
-
|
|
870
|
+
import { lint as lintSync } from "markdownlint/sync";
|
|
871
|
+
|
|
872
|
+
const results = lintSync(options);
|
|
873
|
+
console.log(results.toString());
|
|
849
874
|
```
|
|
850
875
|
|
|
851
|
-
To examine the `result` object directly:
|
|
876
|
+
To examine the `result` object directly via a `Promise`-based call:
|
|
852
877
|
|
|
853
878
|
```javascript
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
});
|
|
879
|
+
import { lint as lintPromise } from "markdownlint/promise";
|
|
880
|
+
|
|
881
|
+
const results = await lintPromise(options);
|
|
882
|
+
console.dir(results, { "colors": true, "depth": null });
|
|
859
883
|
```
|
|
860
884
|
|
|
861
885
|
Output:
|
|
@@ -897,80 +921,10 @@ Output:
|
|
|
897
921
|
```
|
|
898
922
|
|
|
899
923
|
Integration with the [gulp](https://gulpjs.com/) build system is
|
|
900
|
-
straightforward:
|
|
901
|
-
|
|
902
|
-
```javascript
|
|
903
|
-
const gulp = require("gulp");
|
|
904
|
-
const through2 = require("through2");
|
|
905
|
-
const markdownlint = require("markdownlint");
|
|
906
|
-
|
|
907
|
-
gulp.task("markdownlint", function task() {
|
|
908
|
-
return gulp.src("*.md", { "read": false })
|
|
909
|
-
.pipe(through2.obj(function obj(file, enc, next) {
|
|
910
|
-
markdownlint(
|
|
911
|
-
{ "files": [ file.relative ] },
|
|
912
|
-
function callback(err, result) {
|
|
913
|
-
const resultString = (result || "").toString();
|
|
914
|
-
if (resultString) {
|
|
915
|
-
console.log(resultString);
|
|
916
|
-
}
|
|
917
|
-
next(err, file);
|
|
918
|
-
});
|
|
919
|
-
}));
|
|
920
|
-
});
|
|
921
|
-
```
|
|
922
|
-
|
|
923
|
-
Output:
|
|
924
|
-
|
|
925
|
-
```text
|
|
926
|
-
[00:00:00] Starting 'markdownlint'...
|
|
927
|
-
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
|
|
928
|
-
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.md"]
|
|
929
|
-
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This file fails some rules."]
|
|
930
|
-
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
|
|
931
|
-
[00:00:00] Finished 'markdownlint' after 10 ms
|
|
932
|
-
```
|
|
924
|
+
straightforward: [`gulpfile.cjs`](example/gulpfile.cjs).
|
|
933
925
|
|
|
934
926
|
Integration with the [Grunt](https://gruntjs.com/) build system is similar:
|
|
935
|
-
|
|
936
|
-
```javascript
|
|
937
|
-
const markdownlint = require("markdownlint");
|
|
938
|
-
|
|
939
|
-
module.exports = function wrapper(grunt) {
|
|
940
|
-
grunt.initConfig({
|
|
941
|
-
"markdownlint": {
|
|
942
|
-
"example": {
|
|
943
|
-
"src": [ "*.md" ]
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
grunt.registerMultiTask("markdownlint", function task() {
|
|
949
|
-
const done = this.async();
|
|
950
|
-
markdownlint(
|
|
951
|
-
{ "files": this.filesSrc },
|
|
952
|
-
function callback(err, result) {
|
|
953
|
-
const resultString = err || ((result || "").toString());
|
|
954
|
-
if (resultString) {
|
|
955
|
-
grunt.fail.warn("\n" + resultString + "\n");
|
|
956
|
-
}
|
|
957
|
-
done(!err || !resultString);
|
|
958
|
-
});
|
|
959
|
-
});
|
|
960
|
-
};
|
|
961
|
-
```
|
|
962
|
-
|
|
963
|
-
Output:
|
|
964
|
-
|
|
965
|
-
```text
|
|
966
|
-
Running "markdownlint:example" (markdownlint) task
|
|
967
|
-
Warning:
|
|
968
|
-
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
|
|
969
|
-
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.md"]
|
|
970
|
-
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This file fails some rules."]
|
|
971
|
-
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
|
|
972
|
-
Use --force to continue.
|
|
973
|
-
```
|
|
927
|
+
[`Gruntfile.cjs`](example/Gruntfile.cjs).
|
|
974
928
|
|
|
975
929
|
## Browser
|
|
976
930
|
|
|
@@ -982,11 +936,9 @@ Generate normal and minified scripts with:
|
|
|
982
936
|
npm run build-demo
|
|
983
937
|
```
|
|
984
938
|
|
|
985
|
-
Then reference `markdownlint`
|
|
939
|
+
Then reference the `markdownlint-browser` script:
|
|
986
940
|
|
|
987
941
|
```html
|
|
988
|
-
<script src="demo/micromark-browser.js"></script>
|
|
989
|
-
<script src="demo/micromark-html-browser.js"></script>
|
|
990
942
|
<script src="demo/markdownlint-browser.min.js"></script>
|
|
991
943
|
```
|
|
992
944
|
|
|
@@ -998,7 +950,8 @@ const options = {
|
|
|
998
950
|
"content": "Some Markdown to lint."
|
|
999
951
|
}
|
|
1000
952
|
};
|
|
1001
|
-
|
|
953
|
+
|
|
954
|
+
const results = globalThis.markdownlint.lintSync(options).toString();
|
|
1002
955
|
```
|
|
1003
956
|
|
|
1004
957
|
## Examples
|
package/doc/CustomRules.md
CHANGED
|
@@ -36,7 +36,7 @@ A simple rule implementation using the `micromark` parser to report a violation
|
|
|
36
36
|
for any use of blockquotes might look like:
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
|
-
/** @type import("markdownlint").Rule */
|
|
39
|
+
/** @type {import("markdownlint").Rule} */
|
|
40
40
|
module.exports = {
|
|
41
41
|
"names": [ "any-blockquote-micromark" ],
|
|
42
42
|
"description": "Rule that reports an error for any blockquote",
|
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
|
61
61
|
That same rule implemented using the `markdown-it` parser might look like:
|
|
62
62
|
|
|
63
63
|
```javascript
|
|
64
|
-
/** @type import("markdownlint").Rule */
|
|
64
|
+
/** @type {import("markdownlint").Rule} */
|
|
65
65
|
module.exports = {
|
|
66
66
|
"names": [ "any-blockquote-markdown-it" ],
|
|
67
67
|
"description": "Rule that reports an error for any blockquote",
|
|
@@ -160,8 +160,8 @@ implementation that is resolved when the rule completes. (The value passed to
|
|
|
160
160
|
reported via the `onError` function just like for synchronous rules.
|
|
161
161
|
|
|
162
162
|
**Note**: Asynchronous rules cannot be referenced in a synchronous calling
|
|
163
|
-
context (i.e., `markdownlint
|
|
164
|
-
exception.
|
|
163
|
+
context (i.e., `import { lint } from "markdownlint/sync"`). Attempting to do so
|
|
164
|
+
throws an exception.
|
|
165
165
|
|
|
166
166
|
## Examples
|
|
167
167
|
|
|
@@ -187,8 +187,8 @@ exception.
|
|
|
187
187
|
[markdown-it-token]: https://markdown-it.github.io/markdown-it/#Token
|
|
188
188
|
[markdownlint-rule]: https://www.npmjs.com/search?q=keywords:markdownlint-rule
|
|
189
189
|
[micromark]: https://github.com/micromark/micromark
|
|
190
|
-
[micromark-token]: ../lib/markdownlint.d.
|
|
190
|
+
[micromark-token]: ../lib/markdownlint.d.mts
|
|
191
191
|
[rule-helpers]: https://www.npmjs.com/package/markdownlint-rule-helpers
|
|
192
192
|
[options-custom-rules]: ../README.md#optionscustomrules
|
|
193
193
|
[test-rules]: ../test/rules
|
|
194
|
-
[tokens]: ../test/snapshots/markdownlint-test-custom-rules.
|
|
194
|
+
[tokens]: ../test/snapshots/markdownlint-test-custom-rules.mjs.md
|
package/helpers/README.md
CHANGED
|
@@ -22,8 +22,8 @@ be useful to custom rule authors and may avoid duplicating code.
|
|
|
22
22
|
*None* - The entire body of code is tested to 100% coverage by the core
|
|
23
23
|
`markdownlint` project, so there are no additional tests here.
|
|
24
24
|
|
|
25
|
-
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/v0.
|
|
25
|
+
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/v0.37.0/doc/CustomRules.md
|
|
26
26
|
[jsdoc]: https://en.m.wikipedia.org/wiki/JSDoc
|
|
27
27
|
[markdown]: https://en.wikipedia.org/wiki/Markdown
|
|
28
28
|
[markdownlint]: https://github.com/DavidAnson/markdownlint
|
|
29
|
-
[rules]: https://github.com/DavidAnson/markdownlint/blob/v0.
|
|
29
|
+
[rules]: https://github.com/DavidAnson/markdownlint/blob/v0.37.0/doc/Rules.md
|
|
@@ -4,15 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
const micromark = require("./micromark-helpers.cjs");
|
|
6
6
|
|
|
7
|
-
const { newLineRe, nextLinesRe } = require("./shared.
|
|
7
|
+
const { newLineRe, nextLinesRe } = require("./shared.cjs");
|
|
8
8
|
|
|
9
9
|
module.exports.newLineRe = newLineRe;
|
|
10
10
|
module.exports.nextLinesRe = nextLinesRe;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
/** @typedef {import("
|
|
12
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
13
|
+
/** @typedef {import("markdownlint").RuleOnError} RuleOnError */
|
|
14
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
15
|
+
/** @typedef {import("markdownlint").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
|
|
16
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
17
|
+
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
18
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
19
|
+
/** @typedef {import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} */
|
|
20
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
21
|
+
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
|
|
14
22
|
|
|
15
23
|
// Regular expression for matching common front matter (YAML and TOML)
|
|
24
|
+
// @ts-ignore
|
|
16
25
|
module.exports.frontMatterRe =
|
|
17
26
|
/((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
|
|
18
27
|
|
|
@@ -336,8 +345,8 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => (
|
|
|
336
345
|
/**
|
|
337
346
|
* Returns whether two ranges (or MicromarkTokens) overlap anywhere.
|
|
338
347
|
*
|
|
339
|
-
* @param {FileRange|
|
|
340
|
-
* @param {FileRange|
|
|
348
|
+
* @param {FileRange|MicromarkToken} rangeA Range A.
|
|
349
|
+
* @param {FileRange|MicromarkToken} rangeB Range B.
|
|
341
350
|
* @returns {boolean} True iff the two ranges overlap.
|
|
342
351
|
*/
|
|
343
352
|
module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {
|
|
@@ -364,7 +373,7 @@ module.exports.frontMatterHasTitle =
|
|
|
364
373
|
/**
|
|
365
374
|
* Returns an object with information about reference links and images.
|
|
366
375
|
*
|
|
367
|
-
* @param {
|
|
376
|
+
* @param {MicromarkToken[]} tokens Micromark tokens.
|
|
368
377
|
* @returns {Object} Reference link/image data.
|
|
369
378
|
*/
|
|
370
379
|
function getReferenceLinkImageData(tokens) {
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.
|
|
5
|
+
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
/** @typedef {import("
|
|
7
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
8
|
+
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
|
9
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
10
|
+
/** @typedef {import("markdownlint").MicromarkToken} Token */
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Determines if a Micromark token is within an htmlFlow type.
|
package/helpers/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "markdownlint-rule-helpers",
|
|
3
3
|
"version": "0.27.0",
|
|
4
4
|
"description": "A collection of markdownlint helper functions for custom rules",
|
|
5
|
-
"main": "./helpers.
|
|
5
|
+
"main": "./helpers.cjs",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./helpers.
|
|
7
|
+
".": "./helpers.cjs",
|
|
8
8
|
"./micromark": "./micromark-helpers.cjs"
|
|
9
9
|
},
|
|
10
10
|
"author": "David Anson (https://dlaa.me/)",
|
|
@@ -19,9 +19,6 @@
|
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
21
21
|
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"markdownlint-micromark": "0.1.2"
|
|
24
|
-
},
|
|
25
22
|
"keywords": [
|
|
26
23
|
"markdownlint",
|
|
27
24
|
"markdownlint-rule"
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const helpers = require("../helpers");
|
|
6
|
-
const { filterByTypes } = require("../helpers/micromark-helpers.cjs");
|
|
3
|
+
import { getReferenceLinkImageData as helpersGetReferenceLinkImageData } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByTypes } from "../helpers/micromark-helpers.cjs";
|
|
7
5
|
|
|
8
6
|
/** @type {Map<string, object>} */
|
|
9
7
|
const map = new Map();
|
|
@@ -12,10 +10,10 @@ let params = undefined;
|
|
|
12
10
|
/**
|
|
13
11
|
* Initializes (resets) the cache.
|
|
14
12
|
*
|
|
15
|
-
* @param {import("
|
|
13
|
+
* @param {import("markdownlint").RuleParams} [p] Rule parameters object.
|
|
16
14
|
* @returns {void}
|
|
17
15
|
*/
|
|
18
|
-
function initialize(p) {
|
|
16
|
+
export function initialize(p) {
|
|
19
17
|
map.clear();
|
|
20
18
|
params = p;
|
|
21
19
|
}
|
|
@@ -39,11 +37,11 @@ function getCached(name, getValue) {
|
|
|
39
37
|
/**
|
|
40
38
|
* Filters a list of Micromark tokens by type and caches the result.
|
|
41
39
|
*
|
|
42
|
-
* @param {import("
|
|
40
|
+
* @param {import("markdownlint").MicromarkTokenType[]} types Types to allow.
|
|
43
41
|
* @param {boolean} [htmlFlow] Whether to include htmlFlow content.
|
|
44
|
-
* @returns {import("
|
|
42
|
+
* @returns {import("markdownlint").MicromarkToken[]} Filtered tokens.
|
|
45
43
|
*/
|
|
46
|
-
function filterByTypesCached(types, htmlFlow) {
|
|
44
|
+
export function filterByTypesCached(types, htmlFlow) {
|
|
47
45
|
return getCached(
|
|
48
46
|
// eslint-disable-next-line prefer-rest-params
|
|
49
47
|
JSON.stringify(arguments),
|
|
@@ -56,15 +54,9 @@ function filterByTypesCached(types, htmlFlow) {
|
|
|
56
54
|
*
|
|
57
55
|
* @returns {Object} Reference link and image data object.
|
|
58
56
|
*/
|
|
59
|
-
function getReferenceLinkImageData() {
|
|
57
|
+
export function getReferenceLinkImageData() {
|
|
60
58
|
return getCached(
|
|
61
59
|
getReferenceLinkImageData.name,
|
|
62
|
-
() =>
|
|
60
|
+
() => helpersGetReferenceLinkImageData(params.parsers.micromark.tokens)
|
|
63
61
|
);
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
module.exports = {
|
|
67
|
-
initialize,
|
|
68
|
-
filterByTypesCached,
|
|
69
|
-
getReferenceLinkImageData
|
|
70
|
-
};
|