Skip to content

Commit

Permalink
Merge branch 'main' into feat/preview-in-session-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Apr 18, 2023
2 parents cae96ea + e946c42 commit 1789556
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
31 changes: 16 additions & 15 deletions src/runtime/components/ContentRendererMarkdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
24 changes: 15 additions & 9 deletions src/runtime/transformers/shiki/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,21 @@ export const useShikiHighlighter = createSingleton((opts?: Exclude<ModuleOptions
const lines = await getHighlightedTokens(code, lang, theme)
const { highlights = [], colorMap = {} } = opts || {}

return lines.map((line, lineIndex) => ({
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) {
Expand Down

0 comments on commit 1789556

Please sign in to comment.