@mdit-vue/plugin-frontmatter 0.11.1 → 0.12.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.cjs CHANGED
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const grayMatter = require('gray-matter');
6
4
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
6
 
9
- const grayMatter__default = /*#__PURE__*/_interopDefaultLegacy(grayMatter);
7
+ const grayMatter__default = /*#__PURE__*/_interopDefaultCompat(grayMatter);
10
8
 
11
9
  const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {}) => {
12
10
  const render = md.render.bind(md);
@@ -14,10 +12,19 @@ const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {})
14
12
  const { data, content, excerpt = "" } = grayMatter__default(src, grayMatterOptions);
15
13
  env.content = content;
16
14
  env.frontmatter = {
15
+ // allow providing default value
17
16
  ...env.frontmatter,
18
17
  ...data
19
18
  };
20
- env.excerpt = renderExcerpt && excerpt ? render(excerpt, { ...env }) : excerpt;
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
+ render(excerpt, { ...env })
24
+ ) : (
25
+ // use the raw excerpt directly
26
+ excerpt
27
+ );
21
28
  return render(content, env);
22
29
  };
23
30
  };
@@ -0,0 +1,49 @@
1
+ import MarkdownIt 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: MarkdownIt.PluginWithOptions<FrontmatterPluginOptions>;
48
+
49
+ export { type FrontmatterPluginOptions, frontmatterPlugin };
@@ -0,0 +1,49 @@
1
+ import MarkdownIt 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: MarkdownIt.PluginWithOptions<FrontmatterPluginOptions>;
48
+
49
+ export { type FrontmatterPluginOptions, frontmatterPlugin };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import MarkdownIt from 'markdown-it';
2
2
  import matter from 'gray-matter';
3
3
 
4
- declare type GrayMatterOptions = matter.GrayMatterOption<string, GrayMatterOptions>;
4
+ type GrayMatterOptions = matter.GrayMatterOption<string, GrayMatterOptions>;
5
5
  /**
6
6
  * Options of @mdit-vue/plugin-frontmatter
7
7
  */
@@ -46,4 +46,4 @@ declare module '@mdit-vue/types' {
46
46
  */
47
47
  declare const frontmatterPlugin: MarkdownIt.PluginWithOptions<FrontmatterPluginOptions>;
48
48
 
49
- export { FrontmatterPluginOptions, frontmatterPlugin };
49
+ export { type FrontmatterPluginOptions, frontmatterPlugin };
package/dist/index.mjs CHANGED
@@ -6,10 +6,19 @@ const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {})
6
6
  const { data, content, excerpt = "" } = grayMatter(src, grayMatterOptions);
7
7
  env.content = content;
8
8
  env.frontmatter = {
9
+ // allow providing default value
9
10
  ...env.frontmatter,
10
11
  ...data
11
12
  };
12
- env.excerpt = renderExcerpt && excerpt ? render(excerpt, { ...env }) : excerpt;
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
+ render(excerpt, { ...env })
18
+ ) : (
19
+ // use the raw excerpt directly
20
+ excerpt
21
+ );
13
22
  return render(content, env);
14
23
  };
15
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-frontmatter",
3
- "version": "0.11.1",
3
+ "version": "0.12.1",
4
4
  "description": "A markdown-it plugin to get markdown frontmatter",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -38,13 +38,13 @@
38
38
  "test": "vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@mdit-vue/types": "0.11.0",
42
- "@types/markdown-it": "^12.2.3",
41
+ "@mdit-vue/types": "0.12.0",
42
+ "@types/markdown-it": "^13.0.0",
43
43
  "gray-matter": "^4.0.3",
44
44
  "markdown-it": "^13.0.1"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "98828479d07c7bc52d178a00cdb92c166eff09ee"
49
+ "gitHead": "198a71b2e4175a92843609a63d2a848bddb71740"
50
50
  }