@mdit-vue/shared 0.8.0 → 0.9.2

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/dist/index.cjs CHANGED
@@ -10,7 +10,10 @@ const htmlEscapeMap = {
10
10
  '"': """
11
11
  };
12
12
  const htmlEscapeRegexp = /[&<>'"]/g;
13
- const htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
13
+ const htmlEscape = (str) => str.replace(
14
+ htmlEscapeRegexp,
15
+ (char) => htmlEscapeMap[char]
16
+ );
14
17
 
15
18
  const htmlUnescapeMap = {
16
19
  "&amp;": "&",
@@ -25,7 +28,10 @@ const htmlUnescapeMap = {
25
28
  "&#34;": '"'
26
29
  };
27
30
  const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
28
- const htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
31
+ const htmlUnescape = (str) => str.replace(
32
+ htmlUnescapeRegexp,
33
+ (char) => htmlUnescapeMap[char]
34
+ );
29
35
 
30
36
  const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
31
37
  const children = token.children ?? [];
@@ -33,7 +39,9 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
33
39
  if (shouldAllowHtml) {
34
40
  titleTokenTypes.push("html_inline");
35
41
  }
36
- const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol);
42
+ const titleTokens = children.filter(
43
+ (item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol
44
+ );
37
45
  return titleTokens.reduce((result, item) => {
38
46
  if (shouldEscapeText) {
39
47
  if (item.type === "code_inline" || item.type === "text") {
@@ -65,18 +73,18 @@ const resolveHeadersFromTokens = (tokens, {
65
73
  stack.unshift(header);
66
74
  }
67
75
  };
68
- tokens.forEach((_, idx) => {
69
- const token = tokens[idx];
76
+ for (let i = 0; i < tokens.length; i += 1) {
77
+ const token = tokens[i];
70
78
  if (token?.type !== "heading_open") {
71
- return;
79
+ continue;
72
80
  }
73
81
  const headerLevel = Number.parseInt(token.tag.slice(1), 10);
74
82
  if (!level.includes(headerLevel)) {
75
- return;
83
+ continue;
76
84
  }
77
- const nextToken = tokens[idx + 1];
85
+ const nextToken = tokens[i + 1];
78
86
  if (!nextToken) {
79
- return;
87
+ continue;
80
88
  }
81
89
  const title = resolveTitleFromToken(nextToken, {
82
90
  shouldAllowHtml,
@@ -89,7 +97,7 @@ const resolveHeadersFromTokens = (tokens, {
89
97
  slug,
90
98
  children: []
91
99
  });
92
- });
100
+ }
93
101
  return headers;
94
102
  };
95
103
 
package/dist/index.mjs CHANGED
@@ -6,7 +6,10 @@ const htmlEscapeMap = {
6
6
  '"': "&quot;"
7
7
  };
8
8
  const htmlEscapeRegexp = /[&<>'"]/g;
9
- const htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
9
+ const htmlEscape = (str) => str.replace(
10
+ htmlEscapeRegexp,
11
+ (char) => htmlEscapeMap[char]
12
+ );
10
13
 
11
14
  const htmlUnescapeMap = {
12
15
  "&amp;": "&",
@@ -21,7 +24,10 @@ const htmlUnescapeMap = {
21
24
  "&#34;": '"'
22
25
  };
23
26
  const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
24
- const htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
27
+ const htmlUnescape = (str) => str.replace(
28
+ htmlUnescapeRegexp,
29
+ (char) => htmlUnescapeMap[char]
30
+ );
25
31
 
26
32
  const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
27
33
  const children = token.children ?? [];
@@ -29,7 +35,9 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
29
35
  if (shouldAllowHtml) {
30
36
  titleTokenTypes.push("html_inline");
31
37
  }
32
- const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol);
38
+ const titleTokens = children.filter(
39
+ (item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol
40
+ );
33
41
  return titleTokens.reduce((result, item) => {
34
42
  if (shouldEscapeText) {
35
43
  if (item.type === "code_inline" || item.type === "text") {
@@ -61,18 +69,18 @@ const resolveHeadersFromTokens = (tokens, {
61
69
  stack.unshift(header);
62
70
  }
63
71
  };
64
- tokens.forEach((_, idx) => {
65
- const token = tokens[idx];
72
+ for (let i = 0; i < tokens.length; i += 1) {
73
+ const token = tokens[i];
66
74
  if (token?.type !== "heading_open") {
67
- return;
75
+ continue;
68
76
  }
69
77
  const headerLevel = Number.parseInt(token.tag.slice(1), 10);
70
78
  if (!level.includes(headerLevel)) {
71
- return;
79
+ continue;
72
80
  }
73
- const nextToken = tokens[idx + 1];
81
+ const nextToken = tokens[i + 1];
74
82
  if (!nextToken) {
75
- return;
83
+ continue;
76
84
  }
77
85
  const title = resolveTitleFromToken(nextToken, {
78
86
  shouldAllowHtml,
@@ -85,7 +93,7 @@ const resolveHeadersFromTokens = (tokens, {
85
93
  slug,
86
94
  children: []
87
95
  });
88
- });
96
+ }
89
97
  return headers;
90
98
  };
91
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/shared",
3
- "version": "0.8.0",
3
+ "version": "0.9.2",
4
4
  "description": "Shared utils and types of mdit-vue",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -36,17 +36,12 @@
36
36
  "test": "vitest"
37
37
  },
38
38
  "dependencies": {
39
- "@mdit-vue/types": "0.8.0",
39
+ "@mdit-vue/types": "0.9.2",
40
40
  "@types/markdown-it": "^12.2.3",
41
41
  "markdown-it": "^13.0.1"
42
42
  },
43
- "devDependencies": {
44
- "c8": "^7.12.0",
45
- "unbuild": "^0.7.6",
46
- "vitest": "^0.18.1"
47
- },
48
43
  "publishConfig": {
49
44
  "access": "public"
50
45
  },
51
- "gitHead": "7fd357a18b8bcc347cf17e2e78da3b3ed4242e58"
46
+ "gitHead": "11b8e8654846fc959d219dbe89f93c62a4b8f109"
52
47
  }