File tree Expand file tree Collapse file tree 5 files changed +72
-22
lines changed Expand file tree Collapse file tree 5 files changed +72
-22
lines changed Original file line number Diff line number Diff line change @@ -51,10 +51,10 @@ export function createMarkdown(options: ResolvedOptions) {
51
51
52
52
if ( options . frontmatter || options . excerpt ) {
53
53
markdown . use ( frontmatterPlugin , {
54
- renderExcerpt : false ,
54
+ ... options . frontmatterOptions ,
55
55
grayMatterOptions : {
56
56
excerpt : options . excerpt ,
57
- ...options . grayMatterOptions ,
57
+ ...options . frontmatterOptions . grayMatterOptions ,
58
58
} ,
59
59
} )
60
60
}
Original file line number Diff line number Diff line change @@ -8,22 +8,22 @@ export function resolveOptions(userOptions: Options): ResolvedOptions {
8
8
headEnabled : false ,
9
9
headField : '' ,
10
10
frontmatter : true ,
11
- include : null ,
12
- exclude : null ,
13
11
excerpt : false ,
14
12
exposeFrontmatter : true ,
15
13
exposeExcerpt : false ,
16
14
escapeCodeTagInterpolation : true ,
17
15
customSfcBlocks : [ 'route' , 'i18n' , 'style' ] ,
18
16
componentOptions : { } ,
17
+ frontmatterOptions : { } ,
19
18
markdownItOptions : { } ,
20
19
markdownItUses : [ ] ,
21
20
markdownItSetup : ( ) => { } ,
22
- grayMatterOptions : { } ,
23
21
wrapperComponent : null ,
24
22
transforms : { } ,
25
23
vueVersion : userOptions . vueVersion || getVueVersion ( ) ,
26
24
wrapperClasses : 'markdown-body' ,
25
+ include : null ,
26
+ exclude : null ,
27
27
}
28
28
const options = userOptions . frontmatterPreprocess
29
29
? { ...defaultOptions , ...userOptions }
Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ export interface Options {
91
91
*/
92
92
componentOptions ?: ComponentPluginOptions
93
93
94
+ /**
95
+ * Options passed to [@mdit-vue/plugin-frontmatter](https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter)
96
+ */
97
+ frontmatterOptions ?: FrontmatterPluginOptions
98
+
94
99
/**
95
100
* Custom function to provide defaults to the frontmatter and
96
101
* move certain attributes into the "meta" category.
@@ -149,11 +154,6 @@ export interface Options {
149
154
*/
150
155
markdownItSetup ?: ( MarkdownIt : MarkdownIt ) => void
151
156
152
- /**
153
- * Options passed to [gray-matter](https://github.com/jonschlinkert/gray-matter#options)
154
- */
155
- grayMatterOptions ?: FrontmatterPluginOptions [ 'grayMatterOptions' ]
156
-
157
157
/**
158
158
* Class names for wrapper div
159
159
*
Original file line number Diff line number Diff line change 1
1
// Vitest Snapshot v1
2
2
3
- exports [` excerpt > basic- excerpt 1` ] = `
4
- "<template ><div class =\\"markdown-body\\"><p>This is an excerpt.</p>
3
+ exports [` excerpt > raw excerpt 1` ] = `
4
+ "<template ><div class =\\"markdown-body\\"><p>This is an excerpt which is kept as <strong>raw Markdown</strong> .</p>
5
5
<!-- more -->
6
6
<h1>Hello</h1>
7
7
<ul>
@@ -13,10 +13,31 @@ exports[`excerpt > basic-excerpt 1`] = `
13
13
<script setup >
14
14
const frontmatter = { \\" title\\ " :\\" Hey\\ " }
15
15
defineExpose({ frontmatter } )
16
- const excerpt = \\"\\\\nThis is an excerpt.\\\\n\\\\n\\"
16
+ const excerpt = \\"\\\\nThis is an excerpt which is kept as **raw Markdown** .\\\\n\\\\n\\"
17
17
</script >
18
18
<script >
19
19
export const title = \\"Hey\\"
20
- export const excerpt = \\"\\\\nThis is an excerpt.\\\\n\\\\n\\"
20
+ export const excerpt = \\"\\\\nThis is an excerpt which is kept as **raw Markdown**.\\\\n\\\\n\\"
21
+ </script >"
22
+ `;
23
+
24
+ exports[`excerpt > rendered excerpt 1`] = `
25
+ "<template ><div class =\\"markdown-body\\"><p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>
26
+ <!-- more -->
27
+ <h1>Hello</h1>
28
+ <ul>
29
+ <li>A</li>
30
+ <li>B</li>
31
+ <li>C</li>
32
+ </ul>
33
+ </div></template>
34
+ <script setup >
35
+ const frontmatter = { \\" title\\ " :\\" Hey\\ " }
36
+ defineExpose({ frontmatter } )
37
+ const excerpt = \\"<p >This is an excerpt which has been rendered to <strong >HTML</strong >.</p >\\\\n\\"
38
+ </script >
39
+ <script >
40
+ export const title = \\"Hey\\"
41
+ export const excerpt = \\"<p >This is an excerpt which has been rendered to <strong >HTML</strong >.</p >\\\\n\\"
21
42
</script >"
22
43
`;
Original file line number Diff line number Diff line change @@ -3,21 +3,50 @@ import { createMarkdown } from '../src/markdown'
3
3
import { resolveOptions } from '../src/options'
4
4
5
5
describe ( 'excerpt' , ( ) => {
6
- const options = resolveOptions ( {
7
- excerpt : true ,
8
- grayMatterOptions : {
6
+ it ( 'rendered excerpt' , ( ) => {
7
+ const options = resolveOptions ( {
9
8
excerpt : true ,
10
- excerpt_separator : '<!-- more -->' ,
11
- } ,
9
+ frontmatterOptions : {
10
+ grayMatterOptions : {
11
+ excerpt : true ,
12
+ excerpt_separator : '<!-- more -->' ,
13
+ } ,
14
+ } ,
15
+ } )
16
+ const markdownToVue = createMarkdown ( options )
17
+ const md = `---
18
+ title: Hey
19
+ ---
20
+
21
+ This is an excerpt which has been rendered to **HTML**.
22
+
23
+ <!-- more -->
24
+
25
+ # Hello
26
+
27
+ - A
28
+ - B
29
+ - C`
30
+ expect ( markdownToVue ( '' , md ) ) . toMatchSnapshot ( )
12
31
} )
13
- const markdownToVue = createMarkdown ( options )
14
32
15
- it ( 'basic-excerpt' , ( ) => {
33
+ it ( 'raw excerpt' , ( ) => {
34
+ const options = resolveOptions ( {
35
+ excerpt : true ,
36
+ frontmatterOptions : {
37
+ renderExcerpt : false ,
38
+ grayMatterOptions : {
39
+ excerpt : true ,
40
+ excerpt_separator : '<!-- more -->' ,
41
+ } ,
42
+ } ,
43
+ } )
44
+ const markdownToVue = createMarkdown ( options )
16
45
const md = `---
17
46
title: Hey
18
47
---
19
48
20
- This is an excerpt.
49
+ This is an excerpt which is kept as **raw Markdown** .
21
50
22
51
<!-- more -->
23
52
You can’t perform that action at this time.
0 commit comments