Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!fix(MDC): do not generate title/description and toc #354

Merged
merged 1 commit into from
Mar 19, 2025
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
13 changes: 12 additions & 1 deletion src/runtime/components/MDC.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ const props = defineProps({
cacheKey: {
type: String,
default: undefined
},
/**
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
*/
partial: {
type: Boolean,
default: true
}
})

Expand All @@ -81,7 +88,11 @@ const { data, refresh, error } = await useAsyncData(key.value, async () => {
if (typeof props.value !== 'string') {
return props.value
}
return await parseMarkdown(props.value, props.parserOptions)
return await parseMarkdown(props.value, {
...props.parserOptions,
toc: props.partial ? false : props.parserOptions?.toc,
contentHeading: props.partial ? false : props.parserOptions?.contentHeading
})
})

const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body)
Expand Down
25 changes: 13 additions & 12 deletions src/runtime/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,29 @@ export const createMarkdownParser = async (inlineOptions: MDCParseOptions = {})
})
})

const result = processedFile?.result as { body: MDCRoot, excerpt: MDCRoot | undefined }
const parsedContent = processedFile?.result as { body: MDCRoot, excerpt: MDCRoot | undefined }

// Update data with processor data
const data = Object.assign(
inlineOptions.contentHeading !== false ? contentHeading(result.body) : {},
inlineOptions.contentHeading !== false ? contentHeading(parsedContent.body) : {},
frontmatter,
processedFile?.data || {}
) as MDCData

// Generate toc if it is not disabled in front-matter
let toc: Toc | undefined
if (data.toc !== false) {
const tocOption = defu(data.toc || {}, inlineOptions.toc, defaults.toc)
toc = generateToc(result.body, tocOption)
const parsedResult = { data, body: parsedContent.body } as MDCParserResult

// Generate toc if it is not disabled
const userTocOption = data.toc ?? inlineOptions.toc
if (userTocOption !== false) {
const tocOption = defu({} as Toc, userTocOption, defaults.toc)
parsedResult.toc = generateToc(parsedContent.body, tocOption)
}

return {
data,
body: result.body,
excerpt: result.excerpt,
toc
if (parsedContent.excerpt) {
parsedResult.excerpt = parsedContent.excerpt
}

return parsedResult
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface MDCParseOptions {
*/
depth?: number
searchDepth?: number
}
} | false

keepComments?: boolean

Expand Down