eslint-markdown 0.11.0 → 0.12.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/build/configs/all.d.ts +5 -4
- package/build/configs/all.js +54 -0
- package/build/configs/base.d.ts +4 -4
- package/build/configs/base.js +27 -0
- package/{src → build}/configs/index.js +0 -2
- package/build/configs/recommended.d.ts +4 -4
- package/build/configs/recommended.js +36 -0
- package/build/configs/stylistic.d.ts +4 -4
- package/build/configs/stylistic.js +38 -0
- package/build/core/constants.d.ts +6 -5
- package/{src → build}/core/constants.js +1 -8
- package/build/core/types.js +4 -0
- package/build/core/{ast → utils}/escape-string-regexp.d.ts +2 -2
- package/{src/core/ast → build/core/utils}/escape-string-regexp.js +6 -9
- package/build/core/utils/html.d.ts +11 -0
- package/build/core/utils/html.js +31 -0
- package/{src/core/ast → build/core/utils}/index.js +0 -1
- package/build/core/utils/is-blank-line.d.ts +12 -0
- package/{src/core/ast → build/core/utils}/is-blank-line.js +16 -24
- package/build/core/{ast → utils}/skip-ranges.d.ts +6 -7
- package/build/core/utils/skip-ranges.js +33 -0
- package/build/index.d.ts +1393 -16
- package/build/index.js +31 -0
- package/build/rules/allow-heading.d.ts +164 -115
- package/build/rules/allow-heading.js +125 -0
- package/build/rules/allow-image-url.d.ts +51 -45
- package/build/rules/allow-image-url.js +141 -0
- package/build/rules/allow-link-url.d.ts +51 -45
- package/build/rules/allow-link-url.js +141 -0
- package/build/rules/code-lang-shorthand.d.ts +39 -36
- package/build/rules/code-lang-shorthand.js +183 -0
- package/build/rules/consistent-code-style.d.ts +53 -53
- package/build/rules/consistent-code-style.js +198 -0
- package/build/rules/consistent-delete-style.d.ts +30 -27
- package/build/rules/consistent-delete-style.js +84 -0
- package/build/rules/consistent-emphasis-style.d.ts +30 -27
- package/build/rules/consistent-emphasis-style.js +82 -0
- package/build/rules/consistent-inline-code-style.d.ts +19 -16
- package/build/rules/consistent-inline-code-style.js +98 -0
- package/build/rules/consistent-strong-style.d.ts +30 -27
- package/build/rules/consistent-strong-style.js +82 -0
- package/build/rules/consistent-thematic-break-style.d.ts +30 -27
- package/build/rules/consistent-thematic-break-style.js +69 -0
- package/build/rules/consistent-unordered-list-style.d.ts +32 -29
- package/build/rules/consistent-unordered-list-style.js +110 -0
- package/build/rules/en-capitalization.d.ts +35 -33
- package/build/rules/en-capitalization.js +117 -0
- package/build/rules/endline-punctuation.js +2 -0
- package/{src → build}/rules/glossary.js +1 -0
- package/build/rules/index.d.ts +1375 -24
- package/{src → build}/rules/index.js +28 -31
- package/build/rules/no-bold-paragraph.d.ts +17 -15
- package/build/rules/no-bold-paragraph.js +48 -0
- package/build/rules/no-consecutive-blank-line.d.ts +43 -41
- package/build/rules/no-consecutive-blank-line.js +162 -0
- package/build/rules/no-control-character.d.ts +52 -48
- package/build/rules/no-control-character.js +123 -0
- package/build/rules/no-curly-quote.d.ts +44 -39
- package/build/rules/no-curly-quote.js +101 -0
- package/build/rules/no-double-punctuation.d.ts +40 -36
- package/build/rules/no-double-punctuation.js +125 -0
- package/build/rules/no-double-space.d.ts +32 -28
- package/build/rules/no-double-space.js +77 -0
- package/build/rules/no-emoji.d.ts +32 -29
- package/build/rules/no-emoji.js +75 -0
- package/build/rules/no-git-conflict-marker.d.ts +37 -36
- package/build/rules/no-git-conflict-marker.js +95 -0
- package/build/rules/no-irregular-dash.d.ts +49 -46
- package/build/rules/no-irregular-dash.js +108 -0
- package/build/rules/no-irregular-whitespace.d.ts +49 -46
- package/build/rules/no-irregular-whitespace.js +108 -0
- package/build/rules/no-tab.d.ts +48 -45
- package/build/rules/no-tab.js +104 -0
- package/build/rules/no-unmatched-pair.js +2 -0
- package/build/rules/no-url-trailing-slash.d.ts +18 -18
- package/build/rules/no-url-trailing-slash.js +131 -0
- package/build/rules/require-heading-id.d.ts +49 -46
- package/build/rules/require-heading-id.js +187 -0
- package/build/rules/require-image-title.d.ts +33 -30
- package/build/rules/require-image-title.js +99 -0
- package/build/rules/require-link-title.d.ts +33 -30
- package/build/rules/require-link-title.js +102 -0
- package/package.json +8 -11
- package/build/core/ast/html.d.ts +0 -11
- package/build/core/ast/is-blank-line.d.ts +0 -8
- package/src/configs/all.js +0 -67
- package/src/configs/base.js +0 -41
- package/src/configs/recommended.js +0 -50
- package/src/configs/stylistic.js +0 -52
- package/src/core/ast/html.js +0 -53
- package/src/core/ast/skip-ranges.js +0 -51
- package/src/core/types.ts +0 -35
- package/src/index.js +0 -54
- package/src/rules/allow-heading.js +0 -193
- package/src/rules/allow-image-url.js +0 -191
- package/src/rules/allow-link-url.js +0 -191
- package/src/rules/code-lang-shorthand.js +0 -225
- package/src/rules/consistent-code-style.js +0 -260
- package/src/rules/consistent-delete-style.js +0 -118
- package/src/rules/consistent-emphasis-style.js +0 -118
- package/src/rules/consistent-inline-code-style.js +0 -152
- package/src/rules/consistent-strong-style.js +0 -115
- package/src/rules/consistent-thematic-break-style.js +0 -103
- package/src/rules/consistent-unordered-list-style.js +0 -156
- package/src/rules/en-capitalization.js +0 -162
- package/src/rules/endline-punctuation.js +0 -1
- package/src/rules/no-bold-paragraph.js +0 -72
- package/src/rules/no-consecutive-blank-line.js +0 -199
- package/src/rules/no-control-character.js +0 -162
- package/src/rules/no-curly-quote.js +0 -144
- package/src/rules/no-double-punctuation.js +0 -171
- package/src/rules/no-double-space.js +0 -111
- package/src/rules/no-emoji.js +0 -104
- package/src/rules/no-git-conflict-marker.js +0 -133
- package/src/rules/no-irregular-dash.js +0 -143
- package/src/rules/no-irregular-whitespace.js +0 -144
- package/src/rules/no-tab.js +0 -142
- package/src/rules/no-unmatched-pair.js +0 -1
- package/src/rules/no-url-trailing-slash.js +0 -169
- package/src/rules/require-heading-id.js +0 -239
- package/src/rules/require-image-title.js +0 -145
- package/src/rules/require-link-title.js +0 -150
- /package/build/core/{ast → utils}/index.d.ts +0 -0
package/build/configs/all.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @fileoverview `all` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
import markdown from '@eslint/markdown';
|
|
6
|
+
import type { ESLint } from 'eslint';
|
|
5
7
|
export default function all(plugin: ESLint.Plugin): {
|
|
6
8
|
readonly name: "md/all";
|
|
7
9
|
readonly files: ["**/*.md"];
|
|
@@ -14,6 +16,7 @@ export default function all(plugin: ESLint.Plugin): {
|
|
|
14
16
|
};
|
|
15
17
|
readonly language: "markdown/gfm";
|
|
16
18
|
readonly rules: {
|
|
19
|
+
readonly 'md/allow-heading': "error";
|
|
17
20
|
readonly 'md/allow-image-url': "error";
|
|
18
21
|
readonly 'md/allow-link-url': "error";
|
|
19
22
|
readonly 'md/code-lang-shorthand': "error";
|
|
@@ -40,5 +43,3 @@ export default function all(plugin: ESLint.Plugin): {
|
|
|
40
43
|
readonly 'md/require-link-title': "error";
|
|
41
44
|
};
|
|
42
45
|
};
|
|
43
|
-
import type { ESLint } from "eslint";
|
|
44
|
-
import markdown from '@eslint/markdown';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `all` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
4
|
+
*/
|
|
5
|
+
// --------------------------------------------------------------------------------
|
|
6
|
+
// Import
|
|
7
|
+
// --------------------------------------------------------------------------------
|
|
8
|
+
import markdown from '@eslint/markdown';
|
|
9
|
+
// --------------------------------------------------------------------------------
|
|
10
|
+
// Export
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
export default function all(plugin) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'md/all',
|
|
15
|
+
files: ['**/*.md'],
|
|
16
|
+
plugins: {
|
|
17
|
+
markdown,
|
|
18
|
+
get md() {
|
|
19
|
+
return plugin;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
frontmatter: 'yaml',
|
|
24
|
+
},
|
|
25
|
+
language: 'markdown/gfm',
|
|
26
|
+
rules: {
|
|
27
|
+
'md/allow-heading': 'error',
|
|
28
|
+
'md/allow-image-url': 'error',
|
|
29
|
+
'md/allow-link-url': 'error',
|
|
30
|
+
'md/code-lang-shorthand': 'error',
|
|
31
|
+
'md/consistent-code-style': 'error',
|
|
32
|
+
'md/consistent-delete-style': 'error',
|
|
33
|
+
'md/consistent-emphasis-style': 'error',
|
|
34
|
+
'md/consistent-inline-code-style': 'error',
|
|
35
|
+
'md/consistent-strong-style': 'error',
|
|
36
|
+
'md/consistent-thematic-break-style': 'error',
|
|
37
|
+
'md/consistent-unordered-list-style': 'error',
|
|
38
|
+
'md/no-consecutive-blank-line': 'error',
|
|
39
|
+
'md/no-control-character': 'error',
|
|
40
|
+
'md/no-curly-quote': 'error',
|
|
41
|
+
'md/no-double-punctuation': 'error',
|
|
42
|
+
'md/no-double-space': 'error',
|
|
43
|
+
'md/no-emoji': 'error',
|
|
44
|
+
'md/no-git-conflict-marker': 'error',
|
|
45
|
+
'md/no-irregular-dash': 'error',
|
|
46
|
+
'md/no-irregular-whitespace': 'error',
|
|
47
|
+
'md/no-tab': 'error',
|
|
48
|
+
'md/no-url-trailing-slash': 'error',
|
|
49
|
+
'md/require-heading-id': 'error',
|
|
50
|
+
'md/require-image-title': 'error',
|
|
51
|
+
'md/require-link-title': 'error',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
package/build/configs/base.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @fileoverview `base` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
import markdown from '@eslint/markdown';
|
|
6
|
+
import type { ESLint } from 'eslint';
|
|
5
7
|
export default function base(plugin: ESLint.Plugin): {
|
|
6
8
|
readonly name: "md/base";
|
|
7
9
|
readonly files: ["**/*.md"];
|
|
@@ -14,5 +16,3 @@ export default function base(plugin: ESLint.Plugin): {
|
|
|
14
16
|
};
|
|
15
17
|
readonly language: "markdown/gfm";
|
|
16
18
|
};
|
|
17
|
-
import type { ESLint } from "eslint";
|
|
18
|
-
import markdown from '@eslint/markdown';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `base` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
4
|
+
*/
|
|
5
|
+
// --------------------------------------------------------------------------------
|
|
6
|
+
// Import
|
|
7
|
+
// --------------------------------------------------------------------------------
|
|
8
|
+
import markdown from '@eslint/markdown';
|
|
9
|
+
// --------------------------------------------------------------------------------
|
|
10
|
+
// Export
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
export default function base(plugin) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'md/base',
|
|
15
|
+
files: ['**/*.md'],
|
|
16
|
+
plugins: {
|
|
17
|
+
markdown,
|
|
18
|
+
get md() {
|
|
19
|
+
return plugin;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
frontmatter: 'yaml',
|
|
24
|
+
},
|
|
25
|
+
language: 'markdown/gfm',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @fileoverview `recommended` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
import markdown from '@eslint/markdown';
|
|
6
|
+
import type { ESLint } from 'eslint';
|
|
5
7
|
export default function recommended(plugin: ESLint.Plugin): {
|
|
6
8
|
readonly name: "md/recommended";
|
|
7
9
|
readonly files: ["**/*.md"];
|
|
@@ -23,5 +25,3 @@ export default function recommended(plugin: ESLint.Plugin): {
|
|
|
23
25
|
readonly 'md/no-irregular-whitespace': "error";
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
|
-
import type { ESLint } from "eslint";
|
|
27
|
-
import markdown from '@eslint/markdown';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `recommended` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
4
|
+
*/
|
|
5
|
+
// --------------------------------------------------------------------------------
|
|
6
|
+
// Import
|
|
7
|
+
// --------------------------------------------------------------------------------
|
|
8
|
+
import markdown from '@eslint/markdown';
|
|
9
|
+
// --------------------------------------------------------------------------------
|
|
10
|
+
// Export
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
export default function recommended(plugin) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'md/recommended',
|
|
15
|
+
files: ['**/*.md'],
|
|
16
|
+
plugins: {
|
|
17
|
+
markdown,
|
|
18
|
+
get md() {
|
|
19
|
+
return plugin;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
frontmatter: 'yaml',
|
|
24
|
+
},
|
|
25
|
+
language: 'markdown/gfm',
|
|
26
|
+
rules: {
|
|
27
|
+
'md/code-lang-shorthand': 'error',
|
|
28
|
+
'md/no-control-character': 'error',
|
|
29
|
+
'md/no-curly-quote': 'error',
|
|
30
|
+
'md/no-double-space': 'error',
|
|
31
|
+
'md/no-git-conflict-marker': 'error',
|
|
32
|
+
'md/no-irregular-dash': 'error',
|
|
33
|
+
'md/no-irregular-whitespace': 'error',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @fileoverview `stylistic` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
import markdown from '@eslint/markdown';
|
|
6
|
+
import type { ESLint } from 'eslint';
|
|
5
7
|
export default function stylistic(plugin: ESLint.Plugin): {
|
|
6
8
|
readonly name: "md/stylistic";
|
|
7
9
|
readonly files: ["**/*.md"];
|
|
@@ -25,5 +27,3 @@ export default function stylistic(plugin: ESLint.Plugin): {
|
|
|
25
27
|
readonly 'md/no-tab': "error";
|
|
26
28
|
};
|
|
27
29
|
};
|
|
28
|
-
import type { ESLint } from "eslint";
|
|
29
|
-
import markdown from '@eslint/markdown';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `stylistic` configuration.
|
|
3
|
+
* WARNING: This file is autogenerated using the `scripts/build-config.js`
|
|
4
|
+
*/
|
|
5
|
+
// --------------------------------------------------------------------------------
|
|
6
|
+
// Import
|
|
7
|
+
// --------------------------------------------------------------------------------
|
|
8
|
+
import markdown from '@eslint/markdown';
|
|
9
|
+
// --------------------------------------------------------------------------------
|
|
10
|
+
// Export
|
|
11
|
+
// --------------------------------------------------------------------------------
|
|
12
|
+
export default function stylistic(plugin) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'md/stylistic',
|
|
15
|
+
files: ['**/*.md'],
|
|
16
|
+
plugins: {
|
|
17
|
+
markdown,
|
|
18
|
+
get md() {
|
|
19
|
+
return plugin;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
frontmatter: 'yaml',
|
|
24
|
+
},
|
|
25
|
+
language: 'markdown/gfm',
|
|
26
|
+
rules: {
|
|
27
|
+
'md/consistent-code-style': 'error',
|
|
28
|
+
'md/consistent-delete-style': 'error',
|
|
29
|
+
'md/consistent-emphasis-style': 'error',
|
|
30
|
+
'md/consistent-inline-code-style': 'error',
|
|
31
|
+
'md/consistent-strong-style': 'error',
|
|
32
|
+
'md/consistent-thematic-break-style': 'error',
|
|
33
|
+
'md/consistent-unordered-list-style': 'error',
|
|
34
|
+
'md/no-consecutive-blank-line': 'error',
|
|
35
|
+
'md/no-tab': 'error',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const
|
|
5
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This file declares constants used throughout the `eslint-markdown` package.
|
|
3
|
+
*/
|
|
4
|
+
export declare const PKG_NAME: "eslint-markdown";
|
|
5
|
+
export declare const PKG_VERSION: string;
|
|
6
|
+
export declare const URL_RULE_DOCS: (ruleName?: string) => string;
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview This file declares constants used throughout the `eslint-markdown` package.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
// --------------------------------------------------------------------------------
|
|
6
5
|
// Import
|
|
7
6
|
// --------------------------------------------------------------------------------
|
|
8
|
-
|
|
9
7
|
import pkg from '../../package.json' with { type: 'json' };
|
|
10
|
-
|
|
11
8
|
// --------------------------------------------------------------------------------
|
|
12
9
|
// Export
|
|
13
10
|
// --------------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
/** @type {'eslint-markdown'} */
|
|
16
|
-
export const PKG_NAME = /** @type {'eslint-markdown'} */ (pkg.name);
|
|
17
|
-
/** @satisfies {string} */
|
|
11
|
+
export const PKG_NAME = pkg.name;
|
|
18
12
|
export const PKG_VERSION = pkg.version;
|
|
19
|
-
/** Get the URL for the rule documentation based on the rule name. @param {string} [ruleName] */
|
|
20
13
|
export const URL_RULE_DOCS = (ruleName = '') => `${pkg.homepage}/docs/rules/${ruleName}`;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
10
|
+
* @param string A string to escape.
|
|
11
|
+
* @returns An escaped string.
|
|
12
12
|
* @example
|
|
13
13
|
* ```js
|
|
14
14
|
* import escapeStringRegexp from 'path/to/escape-string-regexp.js';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @fileoverview Utility to escape `RegExp` special characters.
|
|
3
3
|
* @see https://github.com/sindresorhus/escape-string-regexp/tree/v5.0.0
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/*
|
|
7
6
|
* MIT License
|
|
8
7
|
*
|
|
@@ -26,18 +25,16 @@
|
|
|
26
25
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
26
|
* SOFTWARE.
|
|
28
27
|
*/
|
|
29
|
-
|
|
30
28
|
// --------------------------------------------------------------------------------
|
|
31
29
|
// Export
|
|
32
30
|
// --------------------------------------------------------------------------------
|
|
33
|
-
|
|
34
31
|
/**
|
|
35
32
|
* Escape `RegExp` special characters.
|
|
36
33
|
*
|
|
37
34
|
* You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.
|
|
38
35
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @returns
|
|
36
|
+
* @param string A string to escape.
|
|
37
|
+
* @returns An escaped string.
|
|
41
38
|
* @example
|
|
42
39
|
* ```js
|
|
43
40
|
* import escapeStringRegexp from 'path/to/escape-string-regexp.js';
|
|
@@ -49,8 +46,8 @@
|
|
|
49
46
|
* ```
|
|
50
47
|
*/
|
|
51
48
|
export default function escapeStringRegexp(string) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
// Escape characters with special meaning either inside or outside character sets.
|
|
50
|
+
// Use a simple backslash escape when it's always valid, and a `\xnn` escape
|
|
51
|
+
// when the simpler form would be disallowed by Unicode patterns' stricter grammar.
|
|
52
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
|
|
56
53
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTML AST utilities.
|
|
3
|
+
*/
|
|
4
|
+
import type { DefaultTreeAdapterTypes } from 'parse5';
|
|
5
|
+
/**
|
|
6
|
+
* Mimics the behavior of `getElementsByTagName` in the DOM API.
|
|
7
|
+
* @param html The HTML string to parse.
|
|
8
|
+
* @param tagName The tag name to search for (case-insensitive).
|
|
9
|
+
* @returns Matched elements.
|
|
10
|
+
*/
|
|
11
|
+
export default function getElementsByTagName(html: string, tagName: string): (DefaultTreeAdapterTypes.Element | DefaultTreeAdapterTypes.Template)[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTML AST utilities.
|
|
3
|
+
*/
|
|
4
|
+
// --------------------------------------------------------------------------------
|
|
5
|
+
// Import
|
|
6
|
+
// --------------------------------------------------------------------------------
|
|
7
|
+
import { parseFragment } from 'parse5';
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
// Export
|
|
10
|
+
// --------------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Mimics the behavior of `getElementsByTagName` in the DOM API.
|
|
13
|
+
* @param html The HTML string to parse.
|
|
14
|
+
* @param tagName The tag name to search for (case-insensitive).
|
|
15
|
+
* @returns Matched elements.
|
|
16
|
+
*/
|
|
17
|
+
export default function getElementsByTagName(html, tagName) {
|
|
18
|
+
const ast = parseFragment(html, { sourceCodeLocationInfo: true });
|
|
19
|
+
const normalizedTagName = tagName.toLowerCase();
|
|
20
|
+
const nodes = [];
|
|
21
|
+
function visit(node) {
|
|
22
|
+
if ('tagName' in node && node.tagName === normalizedTagName) {
|
|
23
|
+
nodes.push(node);
|
|
24
|
+
}
|
|
25
|
+
if ('childNodes' in node) {
|
|
26
|
+
node.childNodes.forEach(visit);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
visit(ast);
|
|
30
|
+
return nodes;
|
|
31
|
+
}
|
|
@@ -2,5 +2,4 @@ import escapeStringRegexp from './escape-string-regexp.js';
|
|
|
2
2
|
import getElementsByTagName from './html.js';
|
|
3
3
|
import isBlankLine from './is-blank-line.js';
|
|
4
4
|
import SkipRanges from './skip-ranges.js';
|
|
5
|
-
|
|
6
5
|
export { escapeStringRegexp, getElementsByTagName, isBlankLine, SkipRanges };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Check if a line is blank.
|
|
3
|
+
* @see https://spec.commonmark.org/0.31.2/#blank-line
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if a line is blank.
|
|
7
|
+
* - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
|
|
8
|
+
* @param str Line string.
|
|
9
|
+
* @param blockquoteDepth The depth of blockquotes. Default is `-1`.
|
|
10
|
+
* @returns `true` if the line is blank. `false` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export default function isBlankLine(str: string, blockquoteDepth?: number): boolean;
|
|
@@ -2,42 +2,34 @@
|
|
|
2
2
|
* @fileoverview Check if a line is blank.
|
|
3
3
|
* @see https://spec.commonmark.org/0.31.2/#blank-line
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
// --------------------------------------------------------------------------------
|
|
7
6
|
// Helper
|
|
8
7
|
// --------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
8
|
const whitespaceChars = new Set([' ', '\t']);
|
|
11
9
|
const blockquoteChar = '>';
|
|
12
|
-
|
|
13
10
|
// --------------------------------------------------------------------------------
|
|
14
11
|
// Export
|
|
15
12
|
// --------------------------------------------------------------------------------
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* Check if a line is blank.
|
|
19
15
|
* - NOTE: The `blockquoteDepth` parameter is zero-based: `0` means one blockquote marker, `1` means two, and so on.
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @returns
|
|
16
|
+
* @param str Line string.
|
|
17
|
+
* @param blockquoteDepth The depth of blockquotes. Default is `-1`.
|
|
18
|
+
* @returns `true` if the line is blank. `false` otherwise.
|
|
23
19
|
*/
|
|
24
20
|
export default function isBlankLine(str, blockquoteDepth = -1) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return false;
|
|
21
|
+
// `.length` is cached for performance.
|
|
22
|
+
const strLength = str.length;
|
|
23
|
+
let remainingBlockquotes = blockquoteDepth + 1;
|
|
24
|
+
for (let i = 0; i < strLength; i++) {
|
|
25
|
+
const char = str[i];
|
|
26
|
+
if (!whitespaceChars.has(char)) {
|
|
27
|
+
if (remainingBlockquotes > 0 && char === blockquoteChar) {
|
|
28
|
+
remainingBlockquotes--;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return true;
|
|
34
|
+
return true;
|
|
43
35
|
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Class to manage skip ranges.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
4
|
+
import type { AST } from 'eslint';
|
|
5
|
+
type SourceRange = AST.Range;
|
|
7
6
|
/**
|
|
8
7
|
* Class to manage skip ranges.
|
|
9
8
|
*/
|
|
10
9
|
export default class SkipRanges {
|
|
10
|
+
#private;
|
|
11
11
|
/**
|
|
12
12
|
* Push a `range` to the set of skip ranges. (Method chaining supported.)
|
|
13
|
-
* @param
|
|
13
|
+
* @param range Source range to skip.
|
|
14
14
|
*/
|
|
15
15
|
push(range: SourceRange): this;
|
|
16
16
|
/**
|
|
17
17
|
* Check whether the `offset` is included in any skip ranges.
|
|
18
|
-
* @param
|
|
18
|
+
* @param offset Offset to check.
|
|
19
19
|
*/
|
|
20
20
|
includes(offset: number): boolean;
|
|
21
|
-
#private;
|
|
22
21
|
}
|
|
23
|
-
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Class to manage skip ranges.
|
|
3
|
+
*/
|
|
4
|
+
// --------------------------------------------------------------------------------
|
|
5
|
+
// Export
|
|
6
|
+
// --------------------------------------------------------------------------------
|
|
7
|
+
/**
|
|
8
|
+
* Class to manage skip ranges.
|
|
9
|
+
*/
|
|
10
|
+
export default class SkipRanges {
|
|
11
|
+
// ------------------------------------------------------------------------------
|
|
12
|
+
// Private Property
|
|
13
|
+
// ------------------------------------------------------------------------------
|
|
14
|
+
#skipRanges = new Set();
|
|
15
|
+
// ------------------------------------------------------------------------------
|
|
16
|
+
// Public Method
|
|
17
|
+
// ------------------------------------------------------------------------------
|
|
18
|
+
/**
|
|
19
|
+
* Push a `range` to the set of skip ranges. (Method chaining supported.)
|
|
20
|
+
* @param range Source range to skip.
|
|
21
|
+
*/
|
|
22
|
+
push(range) {
|
|
23
|
+
this.#skipRanges.add(range);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check whether the `offset` is included in any skip ranges.
|
|
28
|
+
* @param offset Offset to check.
|
|
29
|
+
*/
|
|
30
|
+
includes(offset) {
|
|
31
|
+
return [...this.#skipRanges].some(skipRange => skipRange[0] <= offset && offset < skipRange[1]);
|
|
32
|
+
}
|
|
33
|
+
}
|