@mdit-vue/plugin-headers 2.1.4 → 3.0.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 +44 -21
- package/dist/index.d.cts +42 -41
- package/dist/index.d.mts +42 -41
- package/dist/index.mjs +22 -20
- package/package.json +16 -16
package/dist/index.cjs
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
2
22
|
|
|
3
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
const __mdit_vue_shared = __toESM(require("@mdit-vue/shared"));
|
|
4
25
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
//#region src/headers-plugin.ts
|
|
27
|
+
/**
|
|
28
|
+
* Get markdown headers info
|
|
29
|
+
*
|
|
30
|
+
* Extract them into env
|
|
31
|
+
*/
|
|
32
|
+
const headersPlugin = (md, { level = [2, 3], shouldAllowNested = false, slugify = __mdit_vue_shared.slugify, format } = {}) => {
|
|
33
|
+
const render = md.renderer.render.bind(md.renderer);
|
|
34
|
+
md.renderer.render = (tokens, options, env) => {
|
|
35
|
+
env.headers = (0, __mdit_vue_shared.resolveHeadersFromTokens)(tokens, {
|
|
36
|
+
level,
|
|
37
|
+
shouldAllowHtml: false,
|
|
38
|
+
shouldAllowNested,
|
|
39
|
+
shouldEscapeText: false,
|
|
40
|
+
slugify,
|
|
41
|
+
format
|
|
42
|
+
});
|
|
43
|
+
return render(tokens, options, env);
|
|
44
|
+
};
|
|
23
45
|
};
|
|
24
46
|
|
|
25
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.headersPlugin = headersPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
|
-
import { PluginWithOptions } from
|
|
2
|
-
import { MarkdownItHeader } from
|
|
3
|
-
|
|
1
|
+
import { PluginWithOptions } from "markdown-it";
|
|
2
|
+
import { MarkdownItHeader } from "@mdit-vue/types";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Options of @mdit-vue/plugin-headers
|
|
7
8
|
*/
|
|
8
9
|
interface HeadersPluginOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A custom slugification function
|
|
12
|
+
*
|
|
13
|
+
* Should use the same slugify function with markdown-it-anchor
|
|
14
|
+
* to ensure the link is matched
|
|
15
|
+
*/
|
|
16
|
+
slugify?: (str: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* A function for formatting header title
|
|
19
|
+
*/
|
|
20
|
+
format?: (str: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Heading level that going to be extracted
|
|
23
|
+
*
|
|
24
|
+
* Should be a subset of markdown-it-anchor's `level` option
|
|
25
|
+
* to ensure the slug is existed
|
|
26
|
+
*
|
|
27
|
+
* @default [2,3]
|
|
28
|
+
*/
|
|
29
|
+
level?: number[];
|
|
30
|
+
/**
|
|
31
|
+
* Should allow headers inside nested blocks or not
|
|
32
|
+
*
|
|
33
|
+
* If set to `true`, headers inside blockquote, list, etc. would also be extracted.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
shouldAllowNested?: boolean;
|
|
37
38
|
}
|
|
38
39
|
declare module '@mdit-vue/types' {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
interface MarkdownItEnv {
|
|
41
|
+
/**
|
|
42
|
+
* The headers that extracted by `@mdit-vue/plugin-headers`
|
|
43
|
+
*/
|
|
44
|
+
headers?: MarkdownItHeader[];
|
|
45
|
+
}
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/headers-plugin.d.ts
|
|
47
49
|
/**
|
|
48
50
|
* Get markdown headers info
|
|
49
51
|
*
|
|
50
52
|
* Extract them into env
|
|
51
53
|
*/
|
|
52
54
|
declare const headersPlugin: PluginWithOptions<HeadersPluginOptions>;
|
|
53
|
-
|
|
54
|
-
export { headersPlugin };
|
|
55
|
-
export type { HeadersPluginOptions };
|
|
55
|
+
//#endregion
|
|
56
|
+
export { HeadersPluginOptions, type MarkdownItHeader, headersPlugin };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
|
-
import { PluginWithOptions } from
|
|
2
|
-
import { MarkdownItHeader } from
|
|
3
|
-
|
|
1
|
+
import { PluginWithOptions } from "markdown-it";
|
|
2
|
+
import { MarkdownItHeader } from "@mdit-vue/types";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Options of @mdit-vue/plugin-headers
|
|
7
8
|
*/
|
|
8
9
|
interface HeadersPluginOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A custom slugification function
|
|
12
|
+
*
|
|
13
|
+
* Should use the same slugify function with markdown-it-anchor
|
|
14
|
+
* to ensure the link is matched
|
|
15
|
+
*/
|
|
16
|
+
slugify?: (str: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* A function for formatting header title
|
|
19
|
+
*/
|
|
20
|
+
format?: (str: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Heading level that going to be extracted
|
|
23
|
+
*
|
|
24
|
+
* Should be a subset of markdown-it-anchor's `level` option
|
|
25
|
+
* to ensure the slug is existed
|
|
26
|
+
*
|
|
27
|
+
* @default [2,3]
|
|
28
|
+
*/
|
|
29
|
+
level?: number[];
|
|
30
|
+
/**
|
|
31
|
+
* Should allow headers inside nested blocks or not
|
|
32
|
+
*
|
|
33
|
+
* If set to `true`, headers inside blockquote, list, etc. would also be extracted.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
shouldAllowNested?: boolean;
|
|
37
38
|
}
|
|
38
39
|
declare module '@mdit-vue/types' {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
interface MarkdownItEnv {
|
|
41
|
+
/**
|
|
42
|
+
* The headers that extracted by `@mdit-vue/plugin-headers`
|
|
43
|
+
*/
|
|
44
|
+
headers?: MarkdownItHeader[];
|
|
45
|
+
}
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/headers-plugin.d.ts
|
|
47
49
|
/**
|
|
48
50
|
* Get markdown headers info
|
|
49
51
|
*
|
|
50
52
|
* Extract them into env
|
|
51
53
|
*/
|
|
52
54
|
declare const headersPlugin: PluginWithOptions<HeadersPluginOptions>;
|
|
53
|
-
|
|
54
|
-
export { headersPlugin };
|
|
55
|
-
export type { HeadersPluginOptions };
|
|
55
|
+
//#endregion
|
|
56
|
+
export { HeadersPluginOptions, type MarkdownItHeader, headersPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { resolveHeadersFromTokens, slugify } from
|
|
1
|
+
import { resolveHeadersFromTokens, slugify } from "@mdit-vue/shared";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
//#region src/headers-plugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get markdown headers info
|
|
6
|
+
*
|
|
7
|
+
* Extract them into env
|
|
8
|
+
*/
|
|
9
|
+
const headersPlugin = (md, { level = [2, 3], shouldAllowNested = false, slugify: slugify$1 = slugify, format } = {}) => {
|
|
10
|
+
const render = md.renderer.render.bind(md.renderer);
|
|
11
|
+
md.renderer.render = (tokens, options, env) => {
|
|
12
|
+
env.headers = resolveHeadersFromTokens(tokens, {
|
|
13
|
+
level,
|
|
14
|
+
shouldAllowHtml: false,
|
|
15
|
+
shouldAllowNested,
|
|
16
|
+
shouldEscapeText: false,
|
|
17
|
+
slugify: slugify$1,
|
|
18
|
+
format
|
|
19
|
+
});
|
|
20
|
+
return render(tokens, options, env);
|
|
21
|
+
};
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
export { headersPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit-vue/plugin-headers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A markdown-it plugin to get markdown headers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -22,37 +22,37 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"import":
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"require": {
|
|
30
|
-
"types": "./dist/index.d.cts",
|
|
31
|
-
"default": "./dist/index.cjs"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
34
29
|
},
|
|
35
30
|
"main": "./dist/index.cjs",
|
|
36
31
|
"module": "./dist/index.mjs",
|
|
37
|
-
"types": "./dist/index.d.
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
38
33
|
"files": [
|
|
39
34
|
"./dist"
|
|
40
35
|
],
|
|
41
36
|
"scripts": {
|
|
42
|
-
"build": "
|
|
37
|
+
"build": "tsdown",
|
|
43
38
|
"test": "vitest"
|
|
44
39
|
},
|
|
45
40
|
"dependencies": {
|
|
46
|
-
"@mdit-vue/shared": "
|
|
47
|
-
"@mdit-vue/types": "
|
|
41
|
+
"@mdit-vue/shared": "3.0.0",
|
|
42
|
+
"@mdit-vue/types": "3.0.0",
|
|
48
43
|
"@types/markdown-it": "^14.1.2",
|
|
49
44
|
"markdown-it": "^14.1.0"
|
|
50
45
|
},
|
|
51
46
|
"devDependencies": {
|
|
52
|
-
"markdown-it-anchor": "^9.2.0"
|
|
47
|
+
"markdown-it-anchor": "^9.2.0",
|
|
48
|
+
"tsdown": "^0.14.0",
|
|
49
|
+
"vitest": "^3.2.4"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.0.0"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "bbb62a47109c2932505b3f570b963f70d590914f"
|
|
58
58
|
}
|