File tree Expand file tree Collapse file tree
Sources/MarkdownToAttributedString Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import Foundation
1515public class AttributedStringFormatter {
1616
1717 public var options : FormattingOptions
18-
18+
1919 private var styles : MarkdownStyles ?
2020
2121 /// Initialize the formatter with a Markdown string and optional styling.
@@ -30,7 +30,7 @@ public class AttributedStringFormatter {
3030 self . styles = styles
3131 self . options = options
3232 }
33-
33+
3434 /// Immediately converts a Markdown string into an `NSAttributedString` with the given styling.
3535 ///
3636 /// - Parameters:
@@ -62,10 +62,10 @@ public class AttributedStringFormatter {
6262
6363 var result = asv. convert ( )
6464
65- if options. trimWhitespace {
65+ if options. trimNewlines {
6666 // Taking care not to butcher a trailing emoji 😅
6767 let nsString = result. string as NSString
68- let nonWhitespace = CharacterSet . whitespacesAndNewlines . inverted
68+ let nonWhitespace = CharacterSet . newlines . inverted
6969
7070 let startRange = nsString. rangeOfCharacter ( from: nonWhitespace)
7171 let endRange = nsString. rangeOfCharacter ( from: nonWhitespace, options: . backwards)
@@ -87,7 +87,7 @@ public class AttributedStringFormatter {
8787 return NSAttributedString ( string: " " , attributes: styles? . baseAttributes)
8888 }
8989 }
90-
90+
9191 return result
9292 }
9393}
Original file line number Diff line number Diff line change @@ -22,18 +22,18 @@ public struct FormattingOptions {
2222 /// When `supportedElementTypes` is a subset of `MarkupType.allCases`, the converter will try to skip any unsupported element types.
2323 public var supportedElementTypes = MarkupType . allCases
2424
25- /// When true, any whitespace at the beginning or end of the formatted attributed string is removed. Off by default.
26- public var trimWhitespace : Bool
25+ /// When true, any newlines at the beginning or end of the formatted attributed string is removed. Off by default.
26+ public var trimNewlines : Bool
2727
2828 public init ( addCustomMarkdownElementAttributes: Bool = false ,
2929 debugLogging: Bool = false ,
3030 supportedElementTypes: [ MarkupType ] = MarkupType . allCases,
31- trimWhitespace : Bool = false )
31+ trimNewlines : Bool = false )
3232 {
3333 self . addCustomMarkdownElementAttributes = addCustomMarkdownElementAttributes
3434 self . debugLogging = debugLogging
3535 self . supportedElementTypes = supportedElementTypes
36- self . trimWhitespace = trimWhitespace
36+ self . trimNewlines = trimNewlines
3737 }
3838
3939 public static var `default` : FormattingOptions {
You can’t perform that action at this time.
0 commit comments