Skip to content

Commit 4a3e44e

Browse files
committed
Changed option to just trim newlines, not all whitespace
1 parent fca1a53 commit 4a3e44e

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

Sources/MarkdownToAttributedString/AttributedStringFormatter.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Foundation
1515
public 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
}

Sources/MarkdownToAttributedString/FormattingOptions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)