@mdit-vue/plugin-frontmatter 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.7.0](https://github.com/mdit-vue/mdit-vue/compare/v0.6.0...v0.7.0) (2022-07-18)
7
+
8
+ ### Features
9
+
10
+ - **plugin-frontmatter:** extract content without frontmatter into `env.content` ([a9d5cef](https://github.com/mdit-vue/mdit-vue/commit/a9d5cef9b791bad122cd6e86af0905cab8c2b583))
11
+
6
12
  # [0.6.0](https://github.com/mdit-vue/mdit-vue/compare/v0.5.0...v0.6.0) (2022-07-11)
7
13
 
8
14
  ### Features
package/README.md CHANGED
@@ -7,6 +7,7 @@ A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to get markdo
7
7
 
8
8
  - Extract frontmatter into markdown-it `env.frontmatter`.
9
9
  - Allow providing default frontmatter via markdown-it `env.frontmatter`.
10
+ - Extract markdown content without frontmatter into markdown-it `env.content`.
10
11
  - Support extracting rendered excerpt into markdown-it `env.excerpt`.
11
12
 
12
13
  ## Install
@@ -20,6 +21,7 @@ npm i @mdit-vue/plugin-frontmatter
20
21
  ```ts
21
22
  import MarkdownIt from 'markdown-it';
22
23
  import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
24
+ import type { MarkdownItEnv } from '@mdit-vue/types';
23
25
 
24
26
  const md = MarkdownIt({ html: true }).use(frontmatterPlugin, {
25
27
  // options
package/dist/index.cjs CHANGED
@@ -12,6 +12,7 @@ const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {})
12
12
  const render = md.render.bind(md);
13
13
  md.render = (src, env = {}) => {
14
14
  const { data, content, excerpt = "" } = grayMatter__default(src, grayMatterOptions);
15
+ env.content = content;
15
16
  env.frontmatter = {
16
17
  ...env.frontmatter,
17
18
  ...data
package/dist/index.d.ts CHANGED
@@ -14,12 +14,27 @@ interface FrontmatterPluginOptions {
14
14
  grayMatterOptions?: GrayMatterOptions;
15
15
  /**
16
16
  * Render the excerpt or not
17
+ *
18
+ * @default true
17
19
  */
18
20
  renderExcerpt?: boolean;
19
21
  }
20
22
  declare module '@mdit-vue/types' {
21
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
+ */
22
34
  excerpt?: string;
35
+ /**
36
+ * The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
37
+ */
23
38
  frontmatter?: Record<string, unknown>;
24
39
  }
25
40
  }
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {})
4
4
  const render = md.render.bind(md);
5
5
  md.render = (src, env = {}) => {
6
6
  const { data, content, excerpt = "" } = grayMatter(src, grayMatterOptions);
7
+ env.content = content;
7
8
  env.frontmatter = {
8
9
  ...env.frontmatter,
9
10
  ...data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-frontmatter",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A markdown-it plugin to get markdown frontmatter",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -34,7 +34,7 @@
34
34
  "test": "vitest"
35
35
  },
36
36
  "dependencies": {
37
- "@mdit-vue/types": "0.6.0",
37
+ "@mdit-vue/types": "0.7.0",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "gray-matter": "^4.0.3",
40
40
  "markdown-it": "^13.0.1"
@@ -42,10 +42,10 @@
42
42
  "devDependencies": {
43
43
  "c8": "^7.11.3",
44
44
  "unbuild": "^0.7.4",
45
- "vitest": "^0.18.0"
45
+ "vitest": "^0.18.1"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "654a3a4d52f4fb9711bf5f7ba3674ff58ec663bf"
50
+ "gitHead": "dd30ddd75ca461f775ccc35556132851ebc5e58a"
51
51
  }
@@ -16,6 +16,9 @@ export const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions> = (
16
16
  md.render = (src, env: MarkdownItEnv = {}) => {
17
17
  const { data, content, excerpt = '' } = grayMatter(src, grayMatterOptions);
18
18
 
19
+ // extract stripped content
20
+ env.content = content;
21
+
19
22
  // extract frontmatter
20
23
  env.frontmatter = {
21
24
  // allow providing default value
package/src/types.ts CHANGED
@@ -15,13 +15,30 @@ export interface FrontmatterPluginOptions {
15
15
 
16
16
  /**
17
17
  * Render the excerpt or not
18
+ *
19
+ * @default true
18
20
  */
19
21
  renderExcerpt?: boolean;
20
22
  }
21
23
 
22
24
  declare module '@mdit-vue/types' {
23
25
  interface MarkdownItEnv {
26
+ /**
27
+ * The raw Markdown content without frontmatter
28
+ */
29
+ content?: string;
30
+
31
+ /**
32
+ * The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
33
+ *
34
+ * - Would be the rendered HTML when `renderExcerpt` is enabled
35
+ * - Would be the raw Markdown when `renderExcerpt` is disabled
36
+ */
24
37
  excerpt?: string;
38
+
39
+ /**
40
+ * The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
41
+ */
25
42
  frontmatter?: Record<string, unknown>;
26
43
  }
27
44
  }
@@ -8,6 +8,7 @@ const testCases: {
8
8
  source: string;
9
9
  options: FrontmatterPluginOptions;
10
10
  env: MarkdownItEnv;
11
+ content: MarkdownItEnv['content'];
11
12
  frontmatter: MarkdownItEnv['frontmatter'];
12
13
  excerpt: MarkdownItEnv['excerpt'];
13
14
  }[] = [
@@ -21,6 +22,7 @@ date: 2022-07-06
21
22
  `,
22
23
  options: {},
23
24
  env: {},
25
+ content: '',
24
26
  frontmatter: {
25
27
  str: 'string',
26
28
  num: 123,
@@ -42,6 +44,7 @@ bar: bar
42
44
  baz: 'default-baz',
43
45
  },
44
46
  },
47
+ content: '',
45
48
  frontmatter: {
46
49
  foo: 'foo',
47
50
  bar: 'bar',
@@ -56,6 +59,10 @@ bar: bar
56
59
  `,
57
60
  options: {},
58
61
  env: {},
62
+ content: `\
63
+ # Hello, world
64
+ ---
65
+ `,
59
66
  frontmatter: {},
60
67
  excerpt: '',
61
68
  },
@@ -75,6 +82,10 @@ bar: bar
75
82
  renderExcerpt: true,
76
83
  },
77
84
  env: {},
85
+ content: `\
86
+ # Hello, world
87
+ ---
88
+ `,
78
89
  frontmatter: {
79
90
  foo: 'foo',
80
91
  bar: 'bar',
@@ -98,6 +109,10 @@ bar: bar
98
109
  renderExcerpt: true,
99
110
  },
100
111
  env: {},
112
+ content: `\
113
+ # Hello, world
114
+ <!-- more -->
115
+ `,
101
116
  frontmatter: {
102
117
  foo: 'foo',
103
118
  bar: 'bar',
@@ -121,6 +136,10 @@ bar: bar
121
136
  renderExcerpt: false,
122
137
  },
123
138
  env: {},
139
+ content: `\
140
+ # Hello, world
141
+ <!-- more -->
142
+ `,
124
143
  frontmatter: {
125
144
  foo: 'foo',
126
145
  bar: 'bar',
@@ -131,11 +150,12 @@ bar: bar
131
150
 
132
151
  describe('@mdit-vue/plugin-frontmatter > frontmatter-plugin', () => {
133
152
  testCases.forEach(
134
- ({ source, options, env: rawEnv, frontmatter, excerpt }, i) =>
153
+ ({ source, options, env: rawEnv, content, frontmatter, excerpt }, i) =>
135
154
  it(`case ${i}`, () => {
136
155
  const md = MarkdownIt().use(frontmatterPlugin, options);
137
156
  const env: MarkdownItEnv = { ...rawEnv };
138
157
  md.render(source, env);
158
+ expect(env.content).toEqual(content);
139
159
  expect(env.frontmatter).toEqual(frontmatter);
140
160
  expect(env.excerpt).toEqual(excerpt);
141
161
  }),