diff --git a/src/runtime/components/ContentRendererMarkdown.vue b/src/runtime/components/ContentRendererMarkdown.vue index 74f33d87f..5abc6d32a 100644 --- a/src/runtime/components/ContentRendererMarkdown.vue +++ b/src/runtime/components/ContentRendererMarkdown.vue @@ -57,28 +57,29 @@ export default defineComponent({ const { content: { tags = {} } } = useRuntimeConfig().public const debug = process.dev || useContentPreview().isEnabled() - await resolveContentComponents(props.value.body, { - tags: { - ...tags, - ...toRaw(props.value?._components || {}), - ...props.components - } - }) + let body = (props.value?.body || props.value) as MarkdownNode + if (props.excerpt && props.value?.excerpt) { + body = props.value.excerpt as MarkdownNode + } + if (body) { + await resolveContentComponents(body, { + tags: { + ...tags, + ...toRaw(props.value?._components || {}), + ...props.components + } + }) + } - return { tags, debug } + return { body, debug, tags } }, render (ctx: any) { - const { tags, tag, value, components, debug } = ctx + const { tags, tag, value, components, body, debug } = ctx - if (!value) { + if (!body) { return null } - // Get body from value - let body = (value.body || value) as MarkdownNode - if (ctx.excerpt && value.excerpt) { - body = value.excerpt - } const meta: ParsedContentMeta = { ...(value as ParsedContentMeta), tags: { diff --git a/src/runtime/transformers/shiki/highlighter.ts b/src/runtime/transformers/shiki/highlighter.ts index 40b603d77..4c16c95cf 100644 --- a/src/runtime/transformers/shiki/highlighter.ts +++ b/src/runtime/transformers/shiki/highlighter.ts @@ -146,15 +146,21 @@ export const useShikiHighlighter = createSingleton((opts?: Exclude ({ - type: 'element', - tag: 'div', - props: { - class: ['line', highlights.includes(lineIndex + 1) ? 'highlight' : ''].join(' ').trim(), - line: lineIndex + 1 - }, - children: line.map(tokenSpan) - })) + return lines.map((line, lineIndex) => { + if (lineIndex !== lines.length - 1) { + line[line.length - 1].content += '\n' + } + + return { + type: 'element', + tag: 'span', + props: { + class: ['line', highlights.includes(lineIndex + 1) ? 'highlight' : ''].join(' ').trim(), + line: lineIndex + 1 + }, + children: line.map(tokenSpan) + } + }) function getColorProps (token: { color?: string | object }) { if (!token.color) {