h3 heading support in syntax highlighter

This commit is contained in:
jess 2026-04-05 03:14:32 -07:00
parent 9ed64712f8
commit b1dd8653c9
1 changed files with 15 additions and 0 deletions

View File

@ -1206,6 +1206,21 @@ func applySyntaxHighlighting(to textStorage: NSTextStorage) {
}
private func highlightMarkdownLine(_ trimmed: String, line: String, lineRange: NSRange, textStorage: NSTextStorage, baseFont: NSFont, palette: CatppuccinPalette, isTableHeader: Bool = false) -> Bool {
if trimmed.hasPrefix("### ") {
let hashRange = (textStorage.string as NSString).range(of: "###", range: lineRange)
if hashRange.location != NSNotFound {
textStorage.addAttribute(.foregroundColor, value: palette.overlay0, range: hashRange)
let contentStart = hashRange.location + hashRange.length
let contentRange = NSRange(location: contentStart, length: NSMaxRange(lineRange) - contentStart)
if contentRange.length > 0 {
let h3Font = NSFont.systemFont(ofSize: 15, weight: .bold)
textStorage.addAttribute(.font, value: h3Font, range: contentRange)
textStorage.addAttribute(.foregroundColor, value: palette.text, range: contentRange)
}
}
return true
}
if trimmed.hasPrefix("## ") {
let hashRange = (textStorage.string as NSString).range(of: "##", range: lineRange)
if hashRange.location != NSNotFound {