Skip to content

Commit 9708510

Browse files
committed
fix: fix line higlighting for empty lines
1 parent 6ce88da commit 9708510

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/node/markdown/plugins/highlight.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,28 @@ export async function highlight(
136136
return s
137137
}
138138

139+
const fillEmptyHighlightedLine = (s: string) => {
140+
return s.replace(
141+
/(<span class="line highlighted">)(<\/span>)/g,
142+
'$1<wbr>$2'
143+
)
144+
}
145+
139146
str = removeMustache(str)
140147

141148
const codeToHtml = (theme: IThemeRegistration) => {
142-
return cleanup(
143-
restoreMustache(
144-
lang === 'ansi'
145-
? highlighter.ansiToHtml(str, {
146-
lineOptions,
147-
theme: getThemeName(theme)
148-
})
149-
: highlighter.codeToHtml(str, {
150-
lang,
151-
lineOptions,
152-
theme: getThemeName(theme)
153-
})
154-
)
155-
)
149+
const res =
150+
lang === 'ansi'
151+
? highlighter.ansiToHtml(str, {
152+
lineOptions,
153+
theme: getThemeName(theme)
154+
})
155+
: highlighter.codeToHtml(str, {
156+
lang,
157+
lineOptions,
158+
theme: getThemeName(theme)
159+
})
160+
return fillEmptyHighlightedLine(cleanup(restoreMustache(res)))
156161
}
157162

158163
if (hasSingleTheme) return codeToHtml(theme)

0 commit comments

Comments
 (0)