@mdit-vue/shared 0.11.2 → 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/dist/index.cjs +7 -2
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +7 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,8 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
|
|
|
38
38
|
titleTokenTypes.push("html_inline");
|
|
39
39
|
}
|
|
40
40
|
const titleTokens = children.filter(
|
|
41
|
-
(item) => titleTokenTypes.includes(item.type) &&
|
|
41
|
+
(item) => titleTokenTypes.includes(item.type) && // filter permalink symbol that generated by markdown-it-anchor
|
|
42
|
+
!item.meta?.isPermalinkSymbol
|
|
42
43
|
);
|
|
43
44
|
return titleTokens.reduce((result, item) => {
|
|
44
45
|
if (shouldEscapeText) {
|
|
@@ -53,6 +54,7 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
|
|
|
53
54
|
const resolveHeadersFromTokens = (tokens, {
|
|
54
55
|
level,
|
|
55
56
|
shouldAllowHtml,
|
|
57
|
+
shouldAllowNested,
|
|
56
58
|
shouldEscapeText,
|
|
57
59
|
slugify,
|
|
58
60
|
format
|
|
@@ -73,7 +75,10 @@ const resolveHeadersFromTokens = (tokens, {
|
|
|
73
75
|
};
|
|
74
76
|
for (let i = 0; i < tokens.length; i += 1) {
|
|
75
77
|
const token = tokens[i];
|
|
76
|
-
if (token?.type !== "heading_open"
|
|
78
|
+
if (token?.type !== "heading_open") {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (token?.level !== 0 && !shouldAllowNested) {
|
|
77
82
|
continue;
|
|
78
83
|
}
|
|
79
84
|
const headerLevel = Number.parseInt(token.tag.slice(1), 10);
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,12 @@ interface ResolveHeadersOptions extends ResolveTitleOptions {
|
|
|
39
39
|
* Heading level that going to be resolved
|
|
40
40
|
*/
|
|
41
41
|
level: number[];
|
|
42
|
+
/**
|
|
43
|
+
* Should allow headers inside nested blocks or not
|
|
44
|
+
*
|
|
45
|
+
* If set to `true`, headers inside blockquote, list, etc. would also be resolved.
|
|
46
|
+
*/
|
|
47
|
+
shouldAllowNested: boolean;
|
|
42
48
|
/**
|
|
43
49
|
* A custom slugification function
|
|
44
50
|
*
|
|
@@ -53,7 +59,7 @@ interface ResolveHeadersOptions extends ResolveTitleOptions {
|
|
|
53
59
|
/**
|
|
54
60
|
* Resolve headers from markdown-it tokens
|
|
55
61
|
*/
|
|
56
|
-
declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
|
|
62
|
+
declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldAllowNested, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
|
|
57
63
|
|
|
58
64
|
/**
|
|
59
65
|
* Default slugification function
|
package/dist/index.mjs
CHANGED
|
@@ -36,7 +36,8 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
|
|
|
36
36
|
titleTokenTypes.push("html_inline");
|
|
37
37
|
}
|
|
38
38
|
const titleTokens = children.filter(
|
|
39
|
-
(item) => titleTokenTypes.includes(item.type) &&
|
|
39
|
+
(item) => titleTokenTypes.includes(item.type) && // filter permalink symbol that generated by markdown-it-anchor
|
|
40
|
+
!item.meta?.isPermalinkSymbol
|
|
40
41
|
);
|
|
41
42
|
return titleTokens.reduce((result, item) => {
|
|
42
43
|
if (shouldEscapeText) {
|
|
@@ -51,6 +52,7 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
|
|
|
51
52
|
const resolveHeadersFromTokens = (tokens, {
|
|
52
53
|
level,
|
|
53
54
|
shouldAllowHtml,
|
|
55
|
+
shouldAllowNested,
|
|
54
56
|
shouldEscapeText,
|
|
55
57
|
slugify,
|
|
56
58
|
format
|
|
@@ -71,7 +73,10 @@ const resolveHeadersFromTokens = (tokens, {
|
|
|
71
73
|
};
|
|
72
74
|
for (let i = 0; i < tokens.length; i += 1) {
|
|
73
75
|
const token = tokens[i];
|
|
74
|
-
if (token?.type !== "heading_open"
|
|
76
|
+
if (token?.type !== "heading_open") {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (token?.level !== 0 && !shouldAllowNested) {
|
|
75
80
|
continue;
|
|
76
81
|
}
|
|
77
82
|
const headerLevel = Number.parseInt(token.tag.slice(1), 10);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit-vue/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Shared utils and types of mdit-vue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"test": "vitest"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@mdit-vue/types": "0.
|
|
39
|
+
"@mdit-vue/types": "0.12.0",
|
|
40
40
|
"@types/markdown-it": "^12.2.3",
|
|
41
41
|
"markdown-it": "^13.0.1"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "986b6023d3460cadefd409cd5d4b6445af3a05bd"
|
|
47
47
|
}
|