Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Source/CDMarkdownParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ open class CDMarkdownParser {
// Enables or disables detection of URLs even without Markdown format
open var automaticLinkDetectionEnabled: Bool = true
open var squashNewlines: Bool = true

// Removes whitespace characters on the beginning of each line
open var trimLeadingWhitespaces: Bool = true

public let font: CDFont
public let fontColor: CDColor
public let backgroundColor: CDColor
Expand Down Expand Up @@ -188,15 +192,19 @@ open class CDMarkdownParser {
with: " ",
range: NSRange(location: 0,
length: mutableString.length))
let regExp = try? NSRegularExpression(pattern: "^\\s+",
options: .anchorsMatchLines)
if let regExp = regExp {
regExp.replaceMatches(in: mutableString,
options: [],
range: NSRange(location: 0,
length: mutableString.length),
withTemplate: "")

if trimLeadingWhitespaces {
let regExp = try? NSRegularExpression(pattern: "^\\s+",
options: .anchorsMatchLines)
if let regExp = regExp {
regExp.replaceMatches(in: mutableString,
options: [],
range: NSRange(location: 0,
length: mutableString.length),
withTemplate: "")
}
}

let range = NSRange(location: 0,
length: attributedString.length)

Expand Down