@mdit-vue/plugin-frontmatter 0.7.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-frontmatter",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "A markdown-it plugin to get markdown frontmatter",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "author": "meteorlxy <meteor.lxy@foxmail.com>",
22
+ "type": "module",
22
23
  "exports": {
23
24
  ".": {
24
25
  "types": "./dist/index.d.ts",
@@ -29,23 +30,26 @@
29
30
  "main": "./dist/index.cjs",
30
31
  "module": "./dist/index.mjs",
31
32
  "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "./dist"
35
+ ],
32
36
  "scripts": {
33
37
  "build": "unbuild",
34
38
  "test": "vitest"
35
39
  },
36
40
  "dependencies": {
37
- "@mdit-vue/types": "0.7.0",
41
+ "@mdit-vue/types": "0.7.1",
38
42
  "@types/markdown-it": "^12.2.3",
39
43
  "gray-matter": "^4.0.3",
40
44
  "markdown-it": "^13.0.1"
41
45
  },
42
46
  "devDependencies": {
43
- "c8": "^7.11.3",
44
- "unbuild": "^0.7.4",
47
+ "c8": "^7.12.0",
48
+ "unbuild": "^0.7.6",
45
49
  "vitest": "^0.18.1"
46
50
  },
47
51
  "publishConfig": {
48
52
  "access": "public"
49
53
  },
50
- "gitHead": "dd30ddd75ca461f775ccc35556132851ebc5e58a"
54
+ "gitHead": "b4b8bc6c054ea2dd9ad9ec7a37a58b5a2147b2bd"
51
55
  }
package/CHANGELOG.md DELETED
@@ -1,22 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
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
-
12
- # [0.6.0](https://github.com/mdit-vue/mdit-vue/compare/v0.5.0...v0.6.0) (2022-07-11)
13
-
14
- ### Features
15
-
16
- - **types:** extract types from shared package ([5fc56ce](https://github.com/mdit-vue/mdit-vue/commit/5fc56ce6439159584e09e13ca9a6e87abe8f4389))
17
-
18
- # [0.5.0](https://github.com/mdit-vue/mdit-vue/compare/v0.4.0...v0.5.0) (2022-07-06)
19
-
20
- ### Features
21
-
22
- - **plugin-frontmatter:** add frontmatter plugin ([bcffc7a](https://github.com/mdit-vue/mdit-vue/commit/bcffc7a7fef0c48a869d703f0358d168524ac19e))
package/build.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineBuildConfig } from 'unbuild';
2
-
3
- export default defineBuildConfig({
4
- clean: true,
5
- declaration: true,
6
- entries: ['src/index'],
7
- rollup: {
8
- emitCJS: true,
9
- inlineDependencies: false,
10
- },
11
- });
@@ -1,41 +0,0 @@
1
- import type { MarkdownItEnv } from '@mdit-vue/types';
2
- import grayMatter from 'gray-matter';
3
- import type { PluginWithOptions } from 'markdown-it';
4
- import type { FrontmatterPluginOptions } from './types';
5
-
6
- /**
7
- * Get markdown frontmatter and excerpt
8
- *
9
- * Extract them to env
10
- */
11
- export const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions> = (
12
- md,
13
- { grayMatterOptions, renderExcerpt = true } = {},
14
- ): void => {
15
- const render = md.render.bind(md);
16
- md.render = (src, env: MarkdownItEnv = {}) => {
17
- const { data, content, excerpt = '' } = grayMatter(src, grayMatterOptions);
18
-
19
- // extract stripped content
20
- env.content = content;
21
-
22
- // extract frontmatter
23
- env.frontmatter = {
24
- // allow providing default value
25
- ...env.frontmatter,
26
- ...data,
27
- };
28
-
29
- // render and extract excerpt
30
- env.excerpt =
31
- renderExcerpt && excerpt
32
- ? // render the excerpt with original markdown-it render method.
33
- // here we spread `env` to avoid mutating the original object.
34
- // using deep clone might be a safer choice.
35
- render(excerpt, { ...env })
36
- : // use the raw excerpt directly
37
- excerpt;
38
-
39
- return render(content, env);
40
- };
41
- };
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './frontmatter-plugin';
2
- export * from './types';
package/src/types.ts DELETED
@@ -1,44 +0,0 @@
1
- import type { GrayMatterOption } from 'gray-matter';
2
-
3
- type GrayMatterOptions = GrayMatterOption<string, GrayMatterOptions>;
4
-
5
- /**
6
- * Options of @mdit-vue/plugin-frontmatter
7
- */
8
- export interface FrontmatterPluginOptions {
9
- /**
10
- * Options of gray-matter
11
- *
12
- * @see https://github.com/jonschlinkert/gray-matter#options
13
- */
14
- grayMatterOptions?: GrayMatterOptions;
15
-
16
- /**
17
- * Render the excerpt or not
18
- *
19
- * @default true
20
- */
21
- renderExcerpt?: boolean;
22
- }
23
-
24
- declare module '@mdit-vue/types' {
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
- */
37
- excerpt?: string;
38
-
39
- /**
40
- * The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
41
- */
42
- frontmatter?: Record<string, unknown>;
43
- }
44
- }
@@ -1,163 +0,0 @@
1
- import type { MarkdownItEnv } from '@mdit-vue/types';
2
- import MarkdownIt from 'markdown-it';
3
- import { describe, expect, it } from 'vitest';
4
- import { frontmatterPlugin } from '../src';
5
- import type { FrontmatterPluginOptions } from '../src';
6
-
7
- const testCases: {
8
- source: string;
9
- options: FrontmatterPluginOptions;
10
- env: MarkdownItEnv;
11
- content: MarkdownItEnv['content'];
12
- frontmatter: MarkdownItEnv['frontmatter'];
13
- excerpt: MarkdownItEnv['excerpt'];
14
- }[] = [
15
- {
16
- source: `\
17
- ---
18
- str: string
19
- num: 123
20
- date: 2022-07-06
21
- ---
22
- `,
23
- options: {},
24
- env: {},
25
- content: '',
26
- frontmatter: {
27
- str: 'string',
28
- num: 123,
29
- date: new Date('2022-07-06T00:00:00Z'),
30
- },
31
- excerpt: '',
32
- },
33
- {
34
- source: `\
35
- ---
36
- foo: foo
37
- bar: bar
38
- ---
39
- `,
40
- options: {},
41
- env: {
42
- frontmatter: {
43
- foo: 'default-foo',
44
- baz: 'default-baz',
45
- },
46
- },
47
- content: '',
48
- frontmatter: {
49
- foo: 'foo',
50
- bar: 'bar',
51
- baz: 'default-baz',
52
- },
53
- excerpt: '',
54
- },
55
- {
56
- source: `\
57
- # Hello, world
58
- ---
59
- `,
60
- options: {},
61
- env: {},
62
- content: `\
63
- # Hello, world
64
- ---
65
- `,
66
- frontmatter: {},
67
- excerpt: '',
68
- },
69
- {
70
- source: `\
71
- ---
72
- foo: foo
73
- bar: bar
74
- ---
75
- # Hello, world
76
- ---
77
- `,
78
- options: {
79
- grayMatterOptions: {
80
- excerpt: true,
81
- },
82
- renderExcerpt: true,
83
- },
84
- env: {},
85
- content: `\
86
- # Hello, world
87
- ---
88
- `,
89
- frontmatter: {
90
- foo: 'foo',
91
- bar: 'bar',
92
- },
93
- excerpt: '<h1>Hello, world</h1>\n',
94
- },
95
- {
96
- source: `\
97
- ---
98
- foo: foo
99
- bar: bar
100
- ---
101
- # Hello, world
102
- <!-- more -->
103
- `,
104
- options: {
105
- grayMatterOptions: {
106
- excerpt: true,
107
- excerpt_separator: '<!-- more -->',
108
- },
109
- renderExcerpt: true,
110
- },
111
- env: {},
112
- content: `\
113
- # Hello, world
114
- <!-- more -->
115
- `,
116
- frontmatter: {
117
- foo: 'foo',
118
- bar: 'bar',
119
- },
120
- excerpt: '<h1>Hello, world</h1>\n',
121
- },
122
- {
123
- source: `\
124
- ---
125
- foo: foo
126
- bar: bar
127
- ---
128
- # Hello, world
129
- <!-- more -->
130
- `,
131
- options: {
132
- grayMatterOptions: {
133
- excerpt: true,
134
- excerpt_separator: '<!-- more -->',
135
- },
136
- renderExcerpt: false,
137
- },
138
- env: {},
139
- content: `\
140
- # Hello, world
141
- <!-- more -->
142
- `,
143
- frontmatter: {
144
- foo: 'foo',
145
- bar: 'bar',
146
- },
147
- excerpt: '# Hello, world\n',
148
- },
149
- ];
150
-
151
- describe('@mdit-vue/plugin-frontmatter > frontmatter-plugin', () => {
152
- testCases.forEach(
153
- ({ source, options, env: rawEnv, content, frontmatter, excerpt }, i) =>
154
- it(`case ${i}`, () => {
155
- const md = MarkdownIt().use(frontmatterPlugin, options);
156
- const env: MarkdownItEnv = { ...rawEnv };
157
- md.render(source, env);
158
- expect(env.content).toEqual(content);
159
- expect(env.frontmatter).toEqual(frontmatter);
160
- expect(env.excerpt).toEqual(excerpt);
161
- }),
162
- );
163
- });