Skip to content

Commit 56d83e6

Browse files
committed
Add variable to allow configuration of removal of extra spaces.
1 parent 3d09c81 commit 56d83e6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Aztec/Classes/Libxml2/DOM/Data/TextNode.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class TextNode: Node {
77

88
let contents: String
99

10+
let shouldRemoveExtraSpaces: Bool = false
11+
1012
// MARK: - CustomReflectable
1113

1214
override public var customMirror: Mirror {
@@ -92,10 +94,15 @@ extension TextNode {
9294
// U+000A, which is non-breaking space. We need to maintain it.
9395
//
9496
let whitespace = CharacterSet.whitespacesAndNewlines
95-
let whitespaceToKeep = CharacterSet(charactersIn: String(.nonBreakingSpace)+String(.lineSeparator))
97+
var whitespaceToKeep = CharacterSet(charactersIn: String(.nonBreakingSpace)+String(.lineSeparator))
98+
if ( !shouldRemoveExtraSpaces ) {
99+
whitespaceToKeep.insert(charactersIn: String(.space))
100+
}
96101
let whitespaceToRemove = whitespace.subtracting(whitespaceToKeep)
97-
98102
let trimmedText = text.trimmingCharacters(in: whitespaceToRemove)
103+
if ( !shouldRemoveExtraSpaces ) {
104+
return trimmedText
105+
}
99106
var singleSpaceText = trimmedText
100107
let doubleSpace = " "
101108
let singleSpace = " "
@@ -116,7 +123,6 @@ extension TextNode {
116123
/// - Returns: true if sanitization should happen, false otherwise
117124
///
118125
private func shouldSanitizeText() -> Bool {
119-
return false
120-
//return !hasAncestor(ofType: .pre)
126+
return !hasAncestor(ofType: .pre)
121127
}
122128
}

0 commit comments

Comments
 (0)