@mdit-vue/plugin-frontmatter 0.11.0 → 0.12.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 +11 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +10 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
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; }
|
|
8
|
-
|
|
9
|
-
const grayMatter__default = /*#__PURE__*/_interopDefaultLegacy(grayMatter);
|
|
10
|
-
|
|
11
5
|
const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {}) => {
|
|
12
6
|
const render = md.render.bind(md);
|
|
13
7
|
md.render = (src, env = {}) => {
|
|
14
|
-
const { data, content, excerpt = "" } =
|
|
8
|
+
const { data, content, excerpt = "" } = grayMatter(src, grayMatterOptions);
|
|
15
9
|
env.content = content;
|
|
16
10
|
env.frontmatter = {
|
|
11
|
+
// allow providing default value
|
|
17
12
|
...env.frontmatter,
|
|
18
13
|
...data
|
|
19
14
|
};
|
|
20
|
-
env.excerpt = renderExcerpt && excerpt ?
|
|
15
|
+
env.excerpt = renderExcerpt && excerpt ? (
|
|
16
|
+
// render the excerpt with original markdown-it render method.
|
|
17
|
+
// here we spread `env` to avoid mutating the original object.
|
|
18
|
+
// using deep clone might be a safer choice.
|
|
19
|
+
render(excerpt, { ...env })
|
|
20
|
+
) : (
|
|
21
|
+
// use the raw excerpt directly
|
|
22
|
+
excerpt
|
|
23
|
+
);
|
|
21
24
|
return render(content, env);
|
|
22
25
|
};
|
|
23
26
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import matter from 'gray-matter';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type GrayMatterOptions = matter.GrayMatterOption<string, GrayMatterOptions>;
|
|
5
5
|
/**
|
|
6
6
|
* Options of @mdit-vue/plugin-frontmatter
|
|
7
7
|
*/
|
|
@@ -44,6 +44,6 @@ declare module '@mdit-vue/types' {
|
|
|
44
44
|
*
|
|
45
45
|
* Extract them into env
|
|
46
46
|
*/
|
|
47
|
-
declare const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions>;
|
|
47
|
+
declare const frontmatterPlugin: MarkdownIt.PluginWithOptions<FrontmatterPluginOptions>;
|
|
48
48
|
|
|
49
49
|
export { 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 ?
|
|
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.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "A markdown-it plugin to get markdown frontmatter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "vitest"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@mdit-vue/types": "0.
|
|
41
|
+
"@mdit-vue/types": "0.12.0",
|
|
42
42
|
"@types/markdown-it": "^12.2.3",
|
|
43
43
|
"gray-matter": "^4.0.3",
|
|
44
44
|
"markdown-it": "^13.0.1"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "986b6023d3460cadefd409cd5d4b6445af3a05bd"
|
|
50
50
|
}
|