@mdit-vue/plugin-frontmatter 2.1.3 → 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 +42 -27
- package/dist/index.d.cts +33 -31
- package/dist/index.d.mts +34 -32
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +20 -22
- package/package.json +17 -15
package/dist/index.cjs
CHANGED
|
@@ -1,32 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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));
|
|
6
22
|
|
|
7
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
const gray_matter = __toESM(require("gray-matter"));
|
|
8
25
|
|
|
26
|
+
//#region src/frontmatter-plugin.ts
|
|
27
|
+
/**
|
|
28
|
+
* Get markdown frontmatter and excerpt
|
|
29
|
+
*
|
|
30
|
+
* Extract them into env
|
|
31
|
+
*/
|
|
9
32
|
const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {}) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// here we spread `env` to avoid mutating the original object.
|
|
22
|
-
// using deep clone might be a safer choice.
|
|
23
|
-
render(excerpt, { ...env })
|
|
24
|
-
) : (
|
|
25
|
-
// use the raw excerpt directly
|
|
26
|
-
excerpt
|
|
27
|
-
);
|
|
28
|
-
return render(content, env);
|
|
29
|
-
};
|
|
33
|
+
const parse = md.parse.bind(md);
|
|
34
|
+
md.parse = (src, env = {}) => {
|
|
35
|
+
const { data, content, excerpt = "" } = (0, gray_matter.default)(src, grayMatterOptions);
|
|
36
|
+
env.content = content;
|
|
37
|
+
env.frontmatter = {
|
|
38
|
+
...env.frontmatter,
|
|
39
|
+
...data
|
|
40
|
+
};
|
|
41
|
+
env.excerpt = renderExcerpt && excerpt ? md.render(excerpt, { ...env }) : excerpt;
|
|
42
|
+
return parse(content, env);
|
|
43
|
+
};
|
|
30
44
|
};
|
|
31
45
|
|
|
32
|
-
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.frontmatterPlugin = frontmatterPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import { PluginWithOptions } from
|
|
2
|
-
import matter from
|
|
1
|
+
import { PluginWithOptions } from "markdown-it";
|
|
2
|
+
import matter from "gray-matter";
|
|
3
3
|
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
type GrayMatterOptions = matter.GrayMatterOption<string, GrayMatterOptions>;
|
|
5
6
|
/**
|
|
6
7
|
* Options of @mdit-vue/plugin-frontmatter
|
|
7
8
|
*/
|
|
8
9
|
interface FrontmatterPluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Options of gray-matter
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/jonschlinkert/gray-matter#options
|
|
14
|
+
*/
|
|
15
|
+
grayMatterOptions?: GrayMatterOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Render the excerpt or not
|
|
18
|
+
*
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
renderExcerpt?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare module '@mdit-vue/types' {
|
|
24
|
+
interface MarkdownItEnv {
|
|
9
25
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @see https://github.com/jonschlinkert/gray-matter#options
|
|
26
|
+
* The raw Markdown content without frontmatter
|
|
13
27
|
*/
|
|
14
|
-
|
|
28
|
+
content?: string;
|
|
15
29
|
/**
|
|
16
|
-
*
|
|
30
|
+
* The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
|
|
17
31
|
*
|
|
18
|
-
*
|
|
32
|
+
* - Would be the rendered HTML when `renderExcerpt` is enabled
|
|
33
|
+
* - Would be the raw Markdown when `renderExcerpt` is disabled
|
|
19
34
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
content?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
|
|
30
|
-
*
|
|
31
|
-
* - Would be the rendered HTML when `renderExcerpt` is enabled
|
|
32
|
-
* - Would be the raw Markdown when `renderExcerpt` is disabled
|
|
33
|
-
*/
|
|
34
|
-
excerpt?: string;
|
|
35
|
-
/**
|
|
36
|
-
* The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
|
|
37
|
-
*/
|
|
38
|
-
frontmatter?: Record<string, unknown>;
|
|
39
|
-
}
|
|
35
|
+
excerpt?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
|
|
38
|
+
*/
|
|
39
|
+
frontmatter?: Record<string, unknown>;
|
|
40
|
+
}
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/frontmatter-plugin.d.ts
|
|
42
44
|
/**
|
|
43
45
|
* Get markdown frontmatter and excerpt
|
|
44
46
|
*
|
|
45
47
|
* Extract them into env
|
|
46
48
|
*/
|
|
47
49
|
declare const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions>;
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
+
//#endregion
|
|
51
|
+
export { FrontmatterPluginOptions, frontmatterPlugin };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import grayMatter from "gray-matter";
|
|
2
|
+
import { PluginWithOptions } from "markdown-it";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type GrayMatterOptions = grayMatter.GrayMatterOption<string, GrayMatterOptions>;
|
|
5
6
|
/**
|
|
6
7
|
* Options of @mdit-vue/plugin-frontmatter
|
|
7
8
|
*/
|
|
8
9
|
interface FrontmatterPluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Options of gray-matter
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/jonschlinkert/gray-matter#options
|
|
14
|
+
*/
|
|
15
|
+
grayMatterOptions?: GrayMatterOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Render the excerpt or not
|
|
18
|
+
*
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
renderExcerpt?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare module '@mdit-vue/types' {
|
|
24
|
+
interface MarkdownItEnv {
|
|
9
25
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @see https://github.com/jonschlinkert/gray-matter#options
|
|
26
|
+
* The raw Markdown content without frontmatter
|
|
13
27
|
*/
|
|
14
|
-
|
|
28
|
+
content?: string;
|
|
15
29
|
/**
|
|
16
|
-
*
|
|
30
|
+
* The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
|
|
17
31
|
*
|
|
18
|
-
*
|
|
32
|
+
* - Would be the rendered HTML when `renderExcerpt` is enabled
|
|
33
|
+
* - Would be the raw Markdown when `renderExcerpt` is disabled
|
|
19
34
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
content?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
|
|
30
|
-
*
|
|
31
|
-
* - Would be the rendered HTML when `renderExcerpt` is enabled
|
|
32
|
-
* - Would be the raw Markdown when `renderExcerpt` is disabled
|
|
33
|
-
*/
|
|
34
|
-
excerpt?: string;
|
|
35
|
-
/**
|
|
36
|
-
* The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
|
|
37
|
-
*/
|
|
38
|
-
frontmatter?: Record<string, unknown>;
|
|
39
|
-
}
|
|
35
|
+
excerpt?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
|
|
38
|
+
*/
|
|
39
|
+
frontmatter?: Record<string, unknown>;
|
|
40
|
+
}
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/frontmatter-plugin.d.ts
|
|
42
44
|
/**
|
|
43
45
|
* Get markdown frontmatter and excerpt
|
|
44
46
|
*
|
|
45
47
|
* Extract them into env
|
|
46
48
|
*/
|
|
47
49
|
declare const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions>;
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
+
//#endregion
|
|
51
|
+
export { FrontmatterPluginOptions, frontmatterPlugin };
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import grayMatter from
|
|
1
|
+
import grayMatter from "gray-matter";
|
|
2
2
|
|
|
3
|
+
//#region src/frontmatter-plugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get markdown frontmatter and excerpt
|
|
6
|
+
*
|
|
7
|
+
* Extract them into env
|
|
8
|
+
*/
|
|
3
9
|
const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {}) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// here we spread `env` to avoid mutating the original object.
|
|
16
|
-
// using deep clone might be a safer choice.
|
|
17
|
-
render(excerpt, { ...env })
|
|
18
|
-
) : (
|
|
19
|
-
// use the raw excerpt directly
|
|
20
|
-
excerpt
|
|
21
|
-
);
|
|
22
|
-
return render(content, env);
|
|
23
|
-
};
|
|
10
|
+
const parse = md.parse.bind(md);
|
|
11
|
+
md.parse = (src, env = {}) => {
|
|
12
|
+
const { data, content, excerpt = "" } = grayMatter(src, grayMatterOptions);
|
|
13
|
+
env.content = content;
|
|
14
|
+
env.frontmatter = {
|
|
15
|
+
...env.frontmatter,
|
|
16
|
+
...data
|
|
17
|
+
};
|
|
18
|
+
env.excerpt = renderExcerpt && excerpt ? md.render(excerpt, { ...env }) : excerpt;
|
|
19
|
+
return parse(content, env);
|
|
20
|
+
};
|
|
24
21
|
};
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
export { frontmatterPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit-vue/plugin-frontmatter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A markdown-it plugin to get markdown frontmatter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -22,34 +22,36 @@
|
|
|
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/types": "
|
|
47
|
-
"@types/markdown-it": "^14.1.
|
|
41
|
+
"@mdit-vue/types": "3.0.0",
|
|
42
|
+
"@types/markdown-it": "^14.1.2",
|
|
48
43
|
"gray-matter": "^4.0.3",
|
|
49
44
|
"markdown-it": "^14.1.0"
|
|
50
45
|
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"tsdown": "^0.14.0",
|
|
48
|
+
"vitest": "^3.2.4"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.0.0"
|
|
52
|
+
},
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bbb62a47109c2932505b3f570b963f70d590914f"
|
|
55
57
|
}
|