@mdit-vue/shared 3.0.0 → 3.0.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.d.ts CHANGED
@@ -1,70 +1,84 @@
1
- import { MarkdownItHeader } from '@mdit-vue/types';
2
- import Token from 'markdown-it/lib/token.mjs';
1
+ import { MarkdownItHeader } from "@mdit-vue/types";
2
+ import Token from "markdown-it/lib/token.mjs";
3
3
 
4
+ //#region src/html-escape.d.ts
4
5
  /**
5
6
  * Escape html chars
6
7
  */
7
8
  declare const htmlEscape: (str: string) => string;
8
-
9
+ //#endregion
10
+ //#region src/html-unescape.d.ts
9
11
  /**
10
12
  * Unescape html chars
11
13
  */
12
14
  declare const htmlUnescape: (str: string) => string;
13
-
15
+ //#endregion
16
+ //#region src/resolve-title-from-token.d.ts
14
17
  interface ResolveTitleOptions {
15
- /**
16
- * Should allow inline HTML tags or not.
17
- *
18
- * If the result is going to be used as Vue template, it should allow inline
19
- * HTML tags so that Vue custom components would be kept.
20
- */
21
- shouldAllowHtml: boolean;
22
- /**
23
- * Should escape the text content or not.
24
- *
25
- * If the result is going to be used in HTML directly, it should be escaped
26
- * so that the text content won't be wrongly treated as HTML tags.
27
- */
28
- shouldEscapeText: boolean;
18
+ /**
19
+ * Should allow inline HTML tags or not.
20
+ *
21
+ * If the result is going to be used as Vue template, it should allow inline
22
+ * HTML tags so that Vue custom components would be kept.
23
+ */
24
+ shouldAllowHtml: boolean;
25
+ /**
26
+ * Should escape the text content or not.
27
+ *
28
+ * If the result is going to be used in HTML directly, it should be escaped
29
+ * so that the text content won't be wrongly treated as HTML tags.
30
+ */
31
+ shouldEscapeText: boolean;
29
32
  }
30
33
  /**
31
34
  * Resolve header title from markdown-it token
32
35
  *
33
36
  * Typically using the next token of `heading_open` token
34
37
  */
35
- declare const resolveTitleFromToken: (token: Token, { shouldAllowHtml, shouldEscapeText }: ResolveTitleOptions) => string;
36
-
38
+ declare const resolveTitleFromToken: (token: Token, {
39
+ shouldAllowHtml,
40
+ shouldEscapeText
41
+ }: ResolveTitleOptions) => string;
42
+ //#endregion
43
+ //#region src/resolve-headers-from-tokens.d.ts
37
44
  interface ResolveHeadersOptions extends ResolveTitleOptions {
38
- /**
39
- * Heading level that going to be resolved
40
- */
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;
48
- /**
49
- * A custom slugification function
50
- *
51
- * Would be ignored if the `id` attr of the token is set.
52
- */
53
- slugify: (str: string) => string;
54
- /**
55
- * A function for formatting headings
56
- */
57
- format?: (str: string) => string;
45
+ /**
46
+ * Heading level that going to be resolved
47
+ */
48
+ level: number[];
49
+ /**
50
+ * Should allow headers inside nested blocks or not
51
+ *
52
+ * If set to `true`, headers inside blockquote, list, etc. would also be resolved.
53
+ */
54
+ shouldAllowNested: boolean;
55
+ /**
56
+ * A custom slugification function
57
+ *
58
+ * Would be ignored if the `id` attr of the token is set.
59
+ */
60
+ slugify: (str: string) => string;
61
+ /**
62
+ * A function for formatting headings
63
+ */
64
+ format?: (str: string) => string;
58
65
  }
59
66
  /**
60
67
  * Resolve headers from markdown-it tokens
61
68
  */
62
- declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldAllowNested, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
63
-
69
+ declare const resolveHeadersFromTokens: (tokens: Token[], {
70
+ level,
71
+ shouldAllowHtml,
72
+ shouldAllowNested,
73
+ shouldEscapeText,
74
+ slugify,
75
+ format
76
+ }: ResolveHeadersOptions) => MarkdownItHeader[];
77
+ //#endregion
78
+ //#region src/slugify.d.ts
64
79
  /**
65
80
  * Default slugification function
66
81
  */
67
- declare const slugify: (str: string) => string;
68
-
69
- export { htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify };
70
- export type { ResolveHeadersOptions, ResolveTitleOptions };
82
+ declare const slugify$1: (str: string) => string;
83
+ //#endregion
84
+ export { ResolveHeadersOptions, ResolveTitleOptions, htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify$1 as slugify };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/shared",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Shared utils and types of mdit-vue",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -19,29 +19,27 @@
19
19
  "author": "meteorlxy <meteor.lxy@foxmail.com>",
20
20
  "type": "module",
21
21
  "exports": {
22
- ".": {
23
- "import": "./dist/index.mjs",
24
- "require": "./dist/index.cjs"
25
- },
22
+ ".": "./dist/index.js",
26
23
  "./package.json": "./package.json"
27
24
  },
28
- "main": "./dist/index.cjs",
29
- "module": "./dist/index.mjs",
30
- "types": "./dist/index.d.cts",
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
31
28
  "files": [
32
29
  "./dist"
33
30
  ],
34
31
  "scripts": {
35
32
  "build": "tsdown",
33
+ "clean": "rimraf ./dist",
36
34
  "test": "vitest"
37
35
  },
38
36
  "dependencies": {
39
- "@mdit-vue/types": "3.0.0",
37
+ "@mdit-vue/types": "3.0.2",
40
38
  "@types/markdown-it": "^14.1.2",
41
39
  "markdown-it": "^14.1.0"
42
40
  },
43
41
  "devDependencies": {
44
- "tsdown": "^0.14.0",
42
+ "tsdown": "^0.14.1",
45
43
  "vitest": "^3.2.4"
46
44
  },
47
45
  "engines": {
@@ -50,5 +48,5 @@
50
48
  "publishConfig": {
51
49
  "access": "public"
52
50
  },
53
- "gitHead": "bbb62a47109c2932505b3f570b963f70d590914f"
51
+ "gitHead": "3b5332d09fbd927319bd8be3ba3b86b3d12d1ec8"
54
52
  }
package/dist/index.cjs DELETED
@@ -1,118 +0,0 @@
1
-
2
- //#region src/html-escape.ts
3
- const htmlEscapeMap = {
4
- "&": "&amp;",
5
- "<": "&lt;",
6
- ">": "&gt;",
7
- "'": "&#39;",
8
- "\"": "&quot;"
9
- };
10
- const htmlEscapeRegexp = /[&<>'"]/g;
11
- /**
12
- * Escape html chars
13
- */
14
- const htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
15
-
16
- //#endregion
17
- //#region src/html-unescape.ts
18
- const htmlUnescapeMap = {
19
- "&amp;": "&",
20
- "&#38;": "&",
21
- "&lt;": "<",
22
- "&#60;": "<",
23
- "&gt;": ">",
24
- "&#62;": ">",
25
- "&apos;": "'",
26
- "&#39;": "'",
27
- "&quot;": "\"",
28
- "&#34;": "\""
29
- };
30
- const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
31
- /**
32
- * Unescape html chars
33
- */
34
- const htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
35
-
36
- //#endregion
37
- //#region src/resolve-title-from-token.ts
38
- /**
39
- * Resolve header title from markdown-it token
40
- *
41
- * Typically using the next token of `heading_open` token
42
- */
43
- const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
44
- const children = token.children ?? [];
45
- const titleTokenTypes = [
46
- "text",
47
- "emoji",
48
- "code_inline"
49
- ];
50
- if (shouldAllowHtml) titleTokenTypes.push("html_inline");
51
- const titleTokens = children.filter((item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol);
52
- return titleTokens.reduce((result, item) => {
53
- if (shouldEscapeText) {
54
- if (item.type === "code_inline" || item.type === "text") return `${result}${htmlEscape(item.content)}`;
55
- }
56
- return `${result}${item.content}`;
57
- }, "").trim();
58
- };
59
-
60
- //#endregion
61
- //#region src/resolve-headers-from-tokens.ts
62
- /**
63
- * Resolve headers from markdown-it tokens
64
- */
65
- const resolveHeadersFromTokens = (tokens, { level, shouldAllowHtml, shouldAllowNested, shouldEscapeText, slugify: slugify$1, format }) => {
66
- const headers = [];
67
- const stack = [];
68
- const push = (header) => {
69
- while (stack.length !== 0 && header.level <= stack[0].level) stack.shift();
70
- if (stack.length === 0) {
71
- headers.push(header);
72
- stack.push(header);
73
- } else {
74
- stack[0].children.push(header);
75
- stack.unshift(header);
76
- }
77
- };
78
- for (let i = 0; i < tokens.length; i += 1) {
79
- const token = tokens[i];
80
- if (token.type !== "heading_open") continue;
81
- if (token.level !== 0 && !shouldAllowNested) continue;
82
- const headerLevel = Number.parseInt(token.tag.slice(1), 10);
83
- if (!level.includes(headerLevel)) continue;
84
- const nextToken = tokens[i + 1];
85
- /* istanbul ignore if -- @preserve */
86
- if (!nextToken) continue;
87
- const title = resolveTitleFromToken(nextToken, {
88
- shouldAllowHtml,
89
- shouldEscapeText
90
- });
91
- const slug = token.attrGet("id") ?? slugify$1(title);
92
- push({
93
- level: headerLevel,
94
- title: format?.(title) ?? title,
95
- slug,
96
- link: `#${slug}`,
97
- children: []
98
- });
99
- }
100
- return headers;
101
- };
102
-
103
- //#endregion
104
- //#region src/slugify.ts
105
- const rControl = /[\u0000-\u001f]/g;
106
- const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
107
- const rCombining = /[\u0300-\u036F]/g;
108
- /**
109
- * Default slugification function
110
- */
111
- const slugify = (str) => str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "").replace(/^(\d)/, "_$1").toLowerCase();
112
-
113
- //#endregion
114
- exports.htmlEscape = htmlEscape;
115
- exports.htmlUnescape = htmlUnescape;
116
- exports.resolveHeadersFromTokens = resolveHeadersFromTokens;
117
- exports.resolveTitleFromToken = resolveTitleFromToken;
118
- exports.slugify = slugify;
package/dist/index.d.cts DELETED
@@ -1,84 +0,0 @@
1
- import { MarkdownItHeader } from "@mdit-vue/types";
2
- import Token from "markdown-it/lib/token.mjs";
3
-
4
- //#region src/html-escape.d.ts
5
- /**
6
- * Escape html chars
7
- */
8
- declare const htmlEscape: (str: string) => string;
9
- //#endregion
10
- //#region src/html-unescape.d.ts
11
- /**
12
- * Unescape html chars
13
- */
14
- declare const htmlUnescape: (str: string) => string;
15
- //#endregion
16
- //#region src/resolve-title-from-token.d.ts
17
- interface ResolveTitleOptions {
18
- /**
19
- * Should allow inline HTML tags or not.
20
- *
21
- * If the result is going to be used as Vue template, it should allow inline
22
- * HTML tags so that Vue custom components would be kept.
23
- */
24
- shouldAllowHtml: boolean;
25
- /**
26
- * Should escape the text content or not.
27
- *
28
- * If the result is going to be used in HTML directly, it should be escaped
29
- * so that the text content won't be wrongly treated as HTML tags.
30
- */
31
- shouldEscapeText: boolean;
32
- }
33
- /**
34
- * Resolve header title from markdown-it token
35
- *
36
- * Typically using the next token of `heading_open` token
37
- */
38
- declare const resolveTitleFromToken: (token: Token, {
39
- shouldAllowHtml,
40
- shouldEscapeText
41
- }: ResolveTitleOptions) => string;
42
- //#endregion
43
- //#region src/resolve-headers-from-tokens.d.ts
44
- interface ResolveHeadersOptions extends ResolveTitleOptions {
45
- /**
46
- * Heading level that going to be resolved
47
- */
48
- level: number[];
49
- /**
50
- * Should allow headers inside nested blocks or not
51
- *
52
- * If set to `true`, headers inside blockquote, list, etc. would also be resolved.
53
- */
54
- shouldAllowNested: boolean;
55
- /**
56
- * A custom slugification function
57
- *
58
- * Would be ignored if the `id` attr of the token is set.
59
- */
60
- slugify: (str: string) => string;
61
- /**
62
- * A function for formatting headings
63
- */
64
- format?: (str: string) => string;
65
- }
66
- /**
67
- * Resolve headers from markdown-it tokens
68
- */
69
- declare const resolveHeadersFromTokens: (tokens: Token[], {
70
- level,
71
- shouldAllowHtml,
72
- shouldAllowNested,
73
- shouldEscapeText,
74
- slugify,
75
- format
76
- }: ResolveHeadersOptions) => MarkdownItHeader[];
77
- //#endregion
78
- //#region src/slugify.d.ts
79
- /**
80
- * Default slugification function
81
- */
82
- declare const slugify$1: (str: string) => string;
83
- //#endregion
84
- export { ResolveHeadersOptions, ResolveTitleOptions, htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify$1 as slugify };
package/dist/index.d.mts DELETED
@@ -1,84 +0,0 @@
1
- import { MarkdownItHeader } from "@mdit-vue/types";
2
- import Token from "markdown-it/lib/token.mjs";
3
-
4
- //#region src/html-escape.d.ts
5
- /**
6
- * Escape html chars
7
- */
8
- declare const htmlEscape: (str: string) => string;
9
- //#endregion
10
- //#region src/html-unescape.d.ts
11
- /**
12
- * Unescape html chars
13
- */
14
- declare const htmlUnescape: (str: string) => string;
15
- //#endregion
16
- //#region src/resolve-title-from-token.d.ts
17
- interface ResolveTitleOptions {
18
- /**
19
- * Should allow inline HTML tags or not.
20
- *
21
- * If the result is going to be used as Vue template, it should allow inline
22
- * HTML tags so that Vue custom components would be kept.
23
- */
24
- shouldAllowHtml: boolean;
25
- /**
26
- * Should escape the text content or not.
27
- *
28
- * If the result is going to be used in HTML directly, it should be escaped
29
- * so that the text content won't be wrongly treated as HTML tags.
30
- */
31
- shouldEscapeText: boolean;
32
- }
33
- /**
34
- * Resolve header title from markdown-it token
35
- *
36
- * Typically using the next token of `heading_open` token
37
- */
38
- declare const resolveTitleFromToken: (token: Token, {
39
- shouldAllowHtml,
40
- shouldEscapeText
41
- }: ResolveTitleOptions) => string;
42
- //#endregion
43
- //#region src/resolve-headers-from-tokens.d.ts
44
- interface ResolveHeadersOptions extends ResolveTitleOptions {
45
- /**
46
- * Heading level that going to be resolved
47
- */
48
- level: number[];
49
- /**
50
- * Should allow headers inside nested blocks or not
51
- *
52
- * If set to `true`, headers inside blockquote, list, etc. would also be resolved.
53
- */
54
- shouldAllowNested: boolean;
55
- /**
56
- * A custom slugification function
57
- *
58
- * Would be ignored if the `id` attr of the token is set.
59
- */
60
- slugify: (str: string) => string;
61
- /**
62
- * A function for formatting headings
63
- */
64
- format?: (str: string) => string;
65
- }
66
- /**
67
- * Resolve headers from markdown-it tokens
68
- */
69
- declare const resolveHeadersFromTokens: (tokens: Token[], {
70
- level,
71
- shouldAllowHtml,
72
- shouldAllowNested,
73
- shouldEscapeText,
74
- slugify,
75
- format
76
- }: ResolveHeadersOptions) => MarkdownItHeader[];
77
- //#endregion
78
- //#region src/slugify.d.ts
79
- /**
80
- * Default slugification function
81
- */
82
- declare const slugify$1: (str: string) => string;
83
- //#endregion
84
- export { ResolveHeadersOptions, ResolveTitleOptions, htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify$1 as slugify };
File without changes