eslint-markdown 0.18.0 → 0.18.1

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.
@@ -40,6 +40,12 @@ export declare const escapedTrailingBackslashRegex: RegExp;
40
40
  * @see https://github.com/DavidAnson/markdownlint/blob/v0.41.1/helpers/helpers.cjs#L36-L38
41
41
  */
42
42
  export declare const gemojiRegex: RegExp;
43
+ /**
44
+ * Regular expression for identifying an HTML entity.
45
+ * - NOTE: This pattern is based on `markdownlint`.
46
+ * @see https://github.com/DavidAnson/markdownlint/blob/v0.41.1/helpers/helpers.cjs#L32-L34
47
+ */
48
+ export declare const htmlEntityRegex: RegExp;
43
49
  /**
44
50
  * Matches the closing sequence of a closed ATX heading.
45
51
  * @see https://spec.commonmark.org/0.31.2/#atx-headings
@@ -59,6 +59,12 @@ export const escapedTrailingBackslashRegex = /(?<=(?<!\\)(?:\\{2})*)\\$/u;
59
59
  * @see https://github.com/DavidAnson/markdownlint/blob/v0.41.1/helpers/helpers.cjs#L36-L38
60
60
  */
61
61
  export const gemojiRegex = /:(?:[abmovx]|[-+]1|100|1234|(?:1st|2nd|3rd)_place_medal|8ball|clock\d{1,4}|e-mail|non-potable_water|o2|t-rex|u5272|u5408|u55b6|u6307|u6708|u6709|u6e80|u7121|u7533|u7981|u7a7a|[a-z]{2,15}2?|[a-z]{1,14}(?:_[a-z\d]{1,16})+):/;
62
+ /**
63
+ * Regular expression for identifying an HTML entity.
64
+ * - NOTE: This pattern is based on `markdownlint`.
65
+ * @see https://github.com/DavidAnson/markdownlint/blob/v0.41.1/helpers/helpers.cjs#L32-L34
66
+ */
67
+ export const htmlEntityRegex = /(?<=(?<!\\)(?:\\{2})*)&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);/;
62
68
  /**
63
69
  * Matches the closing sequence of a closed ATX heading.
64
70
  * @see https://spec.commonmark.org/0.31.2/#atx-headings
@@ -6,11 +6,13 @@
6
6
  // Import
7
7
  // --------------------------------------------------------------------------------
8
8
  import { escapeStringRegexp } from '../core/utils/index.js';
9
- import { URL_RULE_DOCS, asciiPunctuationWithQuestionMark } from '../core/constants.js';
9
+ import { URL_RULE_DOCS, asciiPunctuationWithQuestionMark, gemojiRegex as originalGemojiRegex, htmlEntityRegex as originalHtmlEntityRegex, } from '../core/constants.js';
10
10
  // --------------------------------------------------------------------------------
11
11
  // Helper
12
12
  // --------------------------------------------------------------------------------
13
13
  const escapedAsciiPunctuationWithQuestionMark = escapeStringRegexp(asciiPunctuationWithQuestionMark.join(''));
14
+ const gemojiRegex = new RegExp(originalGemojiRegex.source, 'g');
15
+ const htmlEntityRegex = new RegExp(originalHtmlEntityRegex.source, 'g');
14
16
  /**
15
17
  * This pattern is based on the punctuation list used by `remark-lint`.
16
18
  * @see https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-heading-punctuation#parameters
@@ -67,7 +69,11 @@ export default {
67
69
  return {
68
70
  text(node) {
69
71
  const [nodeStartOffset] = sourceCode.getRange(node);
70
- const matches = sourceCode.getText(node).matchAll(doublePunctuationRegex);
72
+ const matches = sourceCode
73
+ .getText(node) // Mask HTML entities and gemoji without changing their offsets in the original text.
74
+ .replace(gemojiRegex, match => ' '.repeat(match.length))
75
+ .replace(htmlEntityRegex, match => ' '.repeat(match.length))
76
+ .matchAll(doublePunctuationRegex);
71
77
  for (const match of matches) {
72
78
  const punctuation = match[0];
73
79
  const startOffset = nodeStartOffset + match.index;
@@ -6,20 +6,12 @@
6
6
  // Import
7
7
  // --------------------------------------------------------------------------------
8
8
  import { escapeStringRegexp } from '../core/utils/index.js';
9
- import { URL_RULE_DOCS, punctuation as defaultPunctuation, escapedTrailingBackslashRegex, gemojiRegex, } from '../core/constants.js';
9
+ import { URL_RULE_DOCS, punctuation as defaultPunctuation, escapedTrailingBackslashRegex, gemojiRegex, htmlEntityRegex, } from '../core/constants.js';
10
10
  // --------------------------------------------------------------------------------
11
11
  // Helper
12
12
  // --------------------------------------------------------------------------------
13
- /**
14
- * Regular expression for identifying a GitHub emoji code at the end of a line.
15
- */
16
13
  const trailingGemojiRegex = new RegExp(`${gemojiRegex.source}$`, gemojiRegex.flags);
17
- /**
18
- * Regular expression for identifying an HTML entity at the end of a line.
19
- * - NOTE: These patterns are based on the `markdownlint`.
20
- * @see https://github.com/DavidAnson/markdownlint/blob/v0.41.1/helpers/helpers.cjs#L32-L34
21
- */
22
- const trailingHtmlEntityRegex = /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
14
+ const trailingHtmlEntityRegex = new RegExp(`${htmlEntityRegex.source}$`, htmlEntityRegex.flags);
23
15
  // --------------------------------------------------------------------------------
24
16
  // Rule Definition
25
17
  // --------------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-markdown",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Lint your Markdown with ESLint. Additional rules for use with `@eslint/markdown`.🛠️",