This repository was archived by the owner on Sep 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +23
-17
lines changed
Expand file tree Collapse file tree 5 files changed +23
-17
lines changed Original file line number Diff line number Diff line change 88
99import UIKit
1010import IGListKit
11+ import StyledText
1112
1213final class IssueCommentCodeBlockCell : IssueCommentBaseCell , ListBindable {
1314
@@ -24,7 +25,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
2425 right: Styles . Sizes. commentGutter
2526 )
2627
27- let textView = AttributedStringView ( )
28+ let textView = StyledTextView ( )
2829 let scrollView = UIScrollView ( )
2930
3031 override init ( frame: CGRect ) {
@@ -67,7 +68,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
6768 let contentSize = viewModel. contentSize
6869 scrollView. contentSize = contentSize
6970
70- textView. configureAndSizeToFit ( text : viewModel. code, width: 0 )
71+ textView. configure ( renderer : viewModel. code, width: 0 )
7172 }
7273
7374}
Original file line number Diff line number Diff line change 88
99import Foundation
1010import IGListKit
11+ import StyledText
1112
1213final class IssueCommentCodeBlockModel : NSObject , ListDiffable {
1314
14- let code : NSAttributedStringSizing
15+ let code : StyledTextRenderer
1516 let language : String ?
1617
1718 init (
18- code: NSAttributedStringSizing ,
19+ code: StyledTextRenderer ,
1920 language: String ?
2021 ) {
2122 self . code = code
@@ -25,7 +26,7 @@ final class IssueCommentCodeBlockModel: NSObject, ListDiffable {
2526 // MARK: Public API
2627
2728 var contentSize : CGSize {
28- return code. textViewSize ( 0 )
29+ return code. viewSize ( width : 0 )
2930 }
3031
3132 // MARK: ListDiffable
Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ private extension Element {
278278 case . hr:
279279 return IssueCommentHrModel ( )
280280 case . codeBlock( let text, let language) :
281- return CodeBlockElement ( text: text, language: language)
281+ return CodeBlockElement ( text: text, language: language, contentSizeCategory : options . contentSizeCategory )
282282 case . heading( let text, let level) :
283283 let builder = StyledTextBuilder . markdownBase ( )
284284 let style : TextStyle
Original file line number Diff line number Diff line change 77//
88
99import Foundation
10+ import StyledText
1011
11- func CodeBlockElement( text: String , language: String ? ) -> IssueCommentCodeBlockModel {
12+ func CodeBlockElement(
13+ text: String ,
14+ language: String ? ,
15+ contentSizeCategory: UIContentSizeCategory
16+ ) -> IssueCommentCodeBlockModel {
1217 let trimmedText = text. trimmingCharacters ( in: . whitespacesAndNewlines)
1318 let attributedString : NSAttributedString
1419
@@ -30,18 +35,17 @@ func CodeBlockElement(text: String, language: String?) -> IssueCommentCodeBlockM
3035 inset. left += IssueCommentCodeBlockCell . scrollViewInset. left
3136 inset. right += IssueCommentCodeBlockCell . scrollViewInset. right
3237
33- // TODO use builder later
34- // let builder = StyledTextBuilder.markdownBase()
35- // .add(attributedText: highlighted)
36-
37- let stringSizing = NSAttributedStringSizing (
38- containerWidth: 0 ,
39- attributedText: attributedString,
38+ let backgroundColor = Styles . Colors. Gray. lighter. color
39+ let builder = StyledTextBuilder ( attributedText: attributedString)
40+ . add ( attributes: [ . backgroundColor: backgroundColor] )
41+ let string = StyledTextRenderer (
42+ string: builder. build ( ) ,
43+ contentSizeCategory: contentSizeCategory,
4044 inset: inset,
41- backgroundColor: Styles . Colors . Gray . lighter . color
45+ backgroundColor: backgroundColor
4246 )
4347 return IssueCommentCodeBlockModel (
44- code: stringSizing ,
48+ code: string ,
4549 language: fixedLanguage
4650 )
4751}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ enum GithubHighlighting {
1313
1414 private static var shared : Highlightr ? = {
1515 let h = Highlightr ( )
16- h? . setTheme ( to: " github " , fontSize: Styles . Text. code. size )
16+ h? . setTheme ( to: " github " , fontSize: Styles . Text. code. preferredFont . pointSize )
1717 return h
1818 } ( )
1919
You can’t perform that action at this time.
0 commit comments