@mdit-vue/plugin-frontmatter 2.1.4 → 3.0.1

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