Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export function createMarkdown(options: ResolvedOptions) {

if (options.frontmatter || options.excerpt) {
markdown.use(frontmatterPlugin, {
renderExcerpt: false,
...options.frontmatterOptions,
grayMatterOptions: {
excerpt: options.excerpt,
...options.grayMatterOptions,
...options.frontmatterOptions.grayMatterOptions,
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ export function resolveOptions(userOptions: Options): ResolvedOptions {
headEnabled: false,
headField: '',
frontmatter: true,
include: null,
exclude: null,
excerpt: false,
exposeFrontmatter: true,
exposeExcerpt: false,
escapeCodeTagInterpolation: true,
customSfcBlocks: ['route', 'i18n', 'style'],
componentOptions: {},
frontmatterOptions: {},
markdownItOptions: {},
markdownItUses: [],
markdownItSetup: () => {},
grayMatterOptions: {},
wrapperComponent: null,
transforms: {},
vueVersion: userOptions.vueVersion || getVueVersion(),
wrapperClasses: 'markdown-body',
include: null,
exclude: null,
}
const options = userOptions.frontmatterPreprocess
? { ...defaultOptions, ...userOptions }
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export interface Options {
*/
componentOptions?: ComponentPluginOptions

/**
* Options passed to [@mdit-vue/plugin-frontmatter](https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter)
*/
frontmatterOptions?: FrontmatterPluginOptions

/**
* Custom function to provide defaults to the frontmatter and
* move certain attributes into the "meta" category.
Expand Down Expand Up @@ -149,11 +154,6 @@ export interface Options {
*/
markdownItSetup?: (MarkdownIt: MarkdownIt) => void

/**
* Options passed to [gray-matter](https://github.com/jonschlinkert/gray-matter#options)
*/
grayMatterOptions?: FrontmatterPluginOptions['grayMatterOptions']

/**
* Class names for wrapper div
*
Expand Down
29 changes: 25 additions & 4 deletions test/__snapshots__/excerpt.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1

exports[`excerpt > basic-excerpt 1`] = `
"<template><div class=\\"markdown-body\\"><p>This is an excerpt.</p>
exports[`excerpt > raw excerpt 1`] = `
"<template><div class=\\"markdown-body\\"><p>This is an excerpt which is kept as <strong>raw Markdown</strong>.</p>
<!-- more -->
<h1>Hello</h1>
<ul>
Expand All @@ -13,10 +13,31 @@ exports[`excerpt > basic-excerpt 1`] = `
<script setup>
const frontmatter = {\\"title\\":\\"Hey\\"}
defineExpose({ frontmatter })
const excerpt = \\"\\\\nThis is an excerpt.\\\\n\\\\n\\"
const excerpt = \\"\\\\nThis is an excerpt which is kept as **raw Markdown**.\\\\n\\\\n\\"
</script>
<script>
export const title = \\"Hey\\"
export const excerpt = \\"\\\\nThis is an excerpt.\\\\n\\\\n\\"
export const excerpt = \\"\\\\nThis is an excerpt which is kept as **raw Markdown**.\\\\n\\\\n\\"
</script>"
`;

exports[`excerpt > rendered excerpt 1`] = `
"<template><div class=\\"markdown-body\\"><p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>
<!-- more -->
<h1>Hello</h1>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</div></template>
<script setup>
const frontmatter = {\\"title\\":\\"Hey\\"}
defineExpose({ frontmatter })
const excerpt = \\"<p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>\\\\n\\"
</script>
<script>
export const title = \\"Hey\\"
export const excerpt = \\"<p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>\\\\n\\"
</script>"
`;
45 changes: 37 additions & 8 deletions test/excerpt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,50 @@ import { createMarkdown } from '../src/markdown'
import { resolveOptions } from '../src/options'

describe('excerpt', () => {
const options = resolveOptions({
excerpt: true,
grayMatterOptions: {
it('rendered excerpt', () => {
const options = resolveOptions({
excerpt: true,
excerpt_separator: '<!-- more -->',
},
frontmatterOptions: {
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
},
})
const markdownToVue = createMarkdown(options)
const md = `---
title: Hey
---

This is an excerpt which has been rendered to **HTML**.

<!-- more -->

# Hello

- A
- B
- C`
expect(markdownToVue('', md)).toMatchSnapshot()
})
const markdownToVue = createMarkdown(options)

it('basic-excerpt', () => {
it('raw excerpt', () => {
const options = resolveOptions({
excerpt: true,
frontmatterOptions: {
renderExcerpt: false,
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
},
})
const markdownToVue = createMarkdown(options)
const md = `---
title: Hey
---

This is an excerpt.
This is an excerpt which is kept as **raw Markdown**.

<!-- more -->

Expand Down