Skip to content

Commit d7fc898

Browse files
committed
Fallback to use unhighlighted code if Highlightr returns undefined
1 parent f2b244d commit d7fc898

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Core/Sources/SuggestionWidget/SyntaxHighlighting.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ func highlighted(code: String, language: String) -> [NSAttributedString] {
3232
)
3333
return convertToCodeLines(formatted)
3434
default:
35+
func unhighlightedCode() -> [NSAttributedString] {
36+
return convertToCodeLines(NSAttributedString(string: code, attributes: [.foregroundColor: NSColor.white]))
37+
}
3538
guard let highlighter = Highlightr() else {
36-
return convertToCodeLines(NSAttributedString(string: code))
39+
return unhighlightedCode()
3740
}
3841
highlighter.setTheme(to: "atom-one-dark")
3942
highlighter.theme.setCodeFont(.monospacedSystemFont(ofSize: 13, weight: .regular))
4043
guard let formatted = highlighter.highlight(code, as: language) else {
41-
return convertToCodeLines(NSAttributedString(string: code))
44+
return unhighlightedCode()
45+
}
46+
if formatted.string == "undefined" {
47+
return unhighlightedCode()
4248
}
4349
return convertToCodeLines(formatted)
4450
}

0 commit comments

Comments
 (0)