@@ -68,31 +68,14 @@ struct MarkupNSAttributedStringVisitor: MarkupVisitor {
6868 // We don't set NSTextList to NSParagraphStyle directly, because NSTextList have abnormal extra spaces.
6969 // ref: https://stackoverflow.com/questions/66714650/nstextlist-formatting
7070
71- var level = 0
72- var parentMarkup : Markup ? = markup. parentMarkup as? ListMarkup
73- while ( parentMarkup != nil ) {
74- if parentMarkup is ListMarkup {
75- level += 1
76- }
77- parentMarkup = parentMarkup? . parentMarkup
78- }
79- let indent = String ( repeating: " \t " , count: level - 1 )
80-
8171 if let parentMarkup = markup. parentMarkup as? ListMarkup {
8272 let thisAttributedString : NSMutableAttributedString
8373 if parentMarkup. styleList. type. isOrder ( ) {
8474 let siblingListItems = markup. parentMarkup? . childMarkups. filter ( { $0 is ListItemMarkup } ) ?? [ ]
8575 let position = ( siblingListItems. firstIndex ( where: { $0 === markup } ) ?? 0 ) + parentMarkup. styleList. startingItemNumber
86- thisAttributedString = NSMutableAttributedString ( attributedString: makeString ( in: markup, string: indent + parentMarkup. styleList. marker ( forItemNumber: position) ) )
76+ thisAttributedString = NSMutableAttributedString ( attributedString: makeString ( in: markup, string: parentMarkup. styleList. marker ( forItemNumber: position) ) )
8777 } else {
88- thisAttributedString = NSMutableAttributedString ( attributedString: makeString ( in: markup, string: indent+ parentMarkup. styleList. marker ( forItemNumber: parentMarkup. styleList. startingItemNumber) ) )
89- }
90-
91- // Since we use \t as an indentation character, the list text cannot contain \t, otherwise it will cause formatting issues, so we replace \t with spaces directly.
92- var tabRange = attributedString. mutableString. range ( of: " \t " , options: . caseInsensitive)
93- while tabRange. location != NSNotFound {
94- attributedString. replaceCharacters ( in: tabRange, with: " " ) // the default width of a \t character is typically equivalent to 8 spaces
95- tabRange = attributedString. mutableString. range ( of: " \t " , options: . caseInsensitive)
78+ thisAttributedString = NSMutableAttributedString ( attributedString: makeString ( in: markup, string: parentMarkup. styleList. marker ( forItemNumber: parentMarkup. styleList. startingItemNumber) ) )
9679 }
9780
9881 attributedString. insert ( thisAttributedString, at: 0 )
0 commit comments