Skip to content

Commit

Permalink
fix(shiki): add \n to empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Apr 18, 2023
1 parent 7541f03 commit 46f3d79
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/runtime/transformers/shiki/highlighter.ts
@@ -1,12 +1,12 @@
import { getHighlighter, BUNDLED_LANGUAGES, BUNDLED_THEMES, Lang, Theme as ShikiTheme, Highlighter } from 'shiki-es'
import consola from 'consola'
import { consola } from 'consola'
import type { ModuleOptions } from '../../../module'
import { createSingleton } from '../utils'
import mdcTMLanguage from './languages/mdc.tmLanguage'
import type { MarkdownNode, HighlighterOptions, Theme, HighlightThemedToken, HighlightThemedTokenLine, TokenColorMap } from './types'

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

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

return lines.map((line, lineIndex) => {
// Add line break to all lines except last
if (lineIndex !== lines.length - 1) {
// Add line break to empty lines
if (line.length === 0) {
line.push({ content: '' })
}
line[line.length - 1].content += '\n'
}

Expand Down

0 comments on commit 46f3d79

Please sign in to comment.