@@ -2,10 +2,15 @@ import AppKit
22import Foundation
33import Highlightr
44import Splash
5- import XPCShared
65import SwiftUI
6+ import XPCShared
77
8- func highlightedCodeBlock( code: String , language: String , brightMode: Bool ) -> NSAttributedString {
8+ func highlightedCodeBlock(
9+ code: String ,
10+ language: String ,
11+ brightMode: Bool ,
12+ fontSize: Double
13+ ) -> NSAttributedString {
914 switch language {
1015 case " swift " :
1116 let plainTextColor = brightMode
@@ -42,7 +47,7 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
4247 )
4348 let formatted = NSMutableAttributedString ( attributedString: highlighter. highlight ( code) )
4449 formatted. addAttributes (
45- [ . font: NSFont . monospacedSystemFont ( ofSize: 13 , weight: . regular) ] ,
50+ [ . font: NSFont . monospacedSystemFont ( ofSize: fontSize , weight: . regular) ] ,
4651 range: NSRange ( location: 0 , length: formatted. length)
4752 )
4853 return formatted
@@ -54,14 +59,17 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
5459 func unhighlightedCode( ) -> NSAttributedString {
5560 return NSAttributedString (
5661 string: code,
57- attributes: [ . foregroundColor: NSColor . white]
62+ attributes: [
63+ . foregroundColor: brightMode ? NSColor . black : NSColor . white,
64+ . font: NSFont . monospacedSystemFont ( ofSize: fontSize, weight: . regular) ,
65+ ]
5866 )
5967 }
6068 guard let highlighter = Highlightr ( ) else {
6169 return unhighlightedCode ( )
6270 }
6371 highlighter. setTheme ( to: brightMode ? " xcode " : " atom-one-dark " )
64- highlighter. theme. setCodeFont ( . monospacedSystemFont( ofSize: 13 , weight: . regular) )
72+ highlighter. theme. setCodeFont ( . monospacedSystemFont( ofSize: fontSize , weight: . regular) )
6573 guard let formatted = highlighter. highlight ( code, as: language) else {
6674 return unhighlightedCode ( )
6775 }
@@ -73,7 +81,12 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
7381}
7482
7583func highlighted( code: String , language: String , brightMode: Bool ) -> [ NSAttributedString ] {
76- let formatted = highlightedCodeBlock ( code: code, language: language, brightMode: brightMode)
84+ let formatted = highlightedCodeBlock (
85+ code: code,
86+ language: language,
87+ brightMode: brightMode,
88+ fontSize: 13
89+ )
7790 let middleDotColor = brightMode
7891 ? NSColor . black. withAlphaComponent ( 0.1 )
7992 : NSColor . white. withAlphaComponent ( 0.1 )
0 commit comments