Skip to content

Commit 46f3d79

Browse files
committed
fix(shiki): add \n to empty lines
1 parent 7541f03 commit 46f3d79

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/runtime/transformers/shiki/highlighter.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { getHighlighter, BUNDLED_LANGUAGES, BUNDLED_THEMES, Lang, Theme as ShikiTheme, Highlighter } from 'shiki-es'
2-
import consola from 'consola'
2+
import { consola } from 'consola'
33
import type { ModuleOptions } from '../../../module'
44
import { createSingleton } from '../utils'
55
import mdcTMLanguage from './languages/mdc.tmLanguage'
66
import type { MarkdownNode, HighlighterOptions, Theme, HighlightThemedToken, HighlightThemedTokenLine, TokenColorMap } from './types'
77

88
// Re-create logger locally as utils cannot be imported from here
9-
const logger = consola.withScope('@nuxt/content')
9+
const logger = consola.withTag('@nuxt/content')
1010

1111
/**
1212
* Resolve Shiki compatible lang from string.
@@ -147,7 +147,12 @@ export const useShikiHighlighter = createSingleton((opts?: Exclude<ModuleOptions
147147
const { highlights = [], colorMap = {} } = opts || {}
148148

149149
return lines.map((line, lineIndex) => {
150+
// Add line break to all lines except last
150151
if (lineIndex !== lines.length - 1) {
152+
// Add line break to empty lines
153+
if (line.length === 0) {
154+
line.push({ content: '' })
155+
}
151156
line[line.length - 1].content += '\n'
152157
}
153158

0 commit comments

Comments
 (0)