@@ -33,25 +33,20 @@ extension NSAppearance {
3333 }
3434}
3535
36- extension MarkdownUI . Theme {
37- static func custom( fontSize: Double ) -> MarkdownUI . Theme {
38- . gitHub. text {
39- ForegroundColor ( . primary)
40- BackgroundColor ( Color . clear)
41- FontSize ( fontSize)
42- }
43- . codeBlock { configuration in
44- ScrollView ( . horizontal) {
45- configuration. label
46- . relativeLineSpacing ( . em( 0.225 ) )
47- . markdownTextStyle {
48- FontFamilyVariant ( . monospaced)
49- FontSize ( . em( 0.85 ) )
50- }
51- . padding ( 16 )
52- . padding ( . top, 14 )
36+ extension View {
37+ func codeBlockLabelStyle( ) -> some View {
38+ self
39+ . relativeLineSpacing ( . em( 0.225 ) )
40+ . markdownTextStyle {
41+ FontFamilyVariant ( . monospaced)
42+ FontSize ( . em( 0.85 ) )
5343 }
54- . workaroundForVerticalScrollingBugInMacOS ( )
44+ . padding ( 16 )
45+ . padding ( . top, 14 )
46+ }
47+
48+ func codeBlockStyle( _ configuration: CodeBlockConfiguration ) -> some View {
49+ self
5550 . background ( Color ( nsColor: . textBackgroundColor) . opacity ( 0.7 ) )
5651 . clipShape ( RoundedRectangle ( cornerRadius: 6 ) )
5752 . overlay ( alignment: . top) {
@@ -69,6 +64,31 @@ extension MarkdownUI.Theme {
6964 }
7065 }
7166 . markdownMargin ( top: 4 , bottom: 16 )
67+ }
68+ }
69+
70+ extension MarkdownUI . Theme {
71+ static func custom( fontSize: Double ) -> MarkdownUI . Theme {
72+ . gitHub. text {
73+ ForegroundColor ( . primary)
74+ BackgroundColor ( Color . clear)
75+ FontSize ( fontSize)
76+ }
77+ . codeBlock { configuration in
78+ let wrapCode = UserDefaults . shared. value ( for: \. wrapCodeInChatCodeBlock)
79+
80+ if wrapCode {
81+ configuration. label
82+ . codeBlockLabelStyle ( )
83+ . codeBlockStyle ( configuration)
84+ } else {
85+ ScrollView ( . horizontal) {
86+ configuration. label
87+ . codeBlockLabelStyle ( )
88+ }
89+ . workaroundForVerticalScrollingBugInMacOS ( )
90+ . codeBlockStyle ( configuration)
91+ }
7292 }
7393 }
7494
0 commit comments