Skip to content

Commit a56f08d

Browse files
Merge pull request #1157 from wordpress-mobile/issue/empty_list
Empty list
2 parents b11a6e4 + 31f6ee0 commit a56f08d

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

Aztec/Classes/Extensions/String+EndOfLine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension String {
99
///
1010
/// - Returns: `true` if the specified index is in an empty line, `false` otherwise.
1111
///
12-
func isEmptyLine(at index: String.Index) -> Bool {
12+
public func isEmptyLine(at index: String.Index) -> Bool {
1313
return isStartOfNewLine(at: index) && isEndOfLine(at: index)
1414
}
1515

@@ -20,7 +20,7 @@ extension String {
2020
///
2121
/// - Returns: `true` if the specified offset is in an empty line, `false` otherwise.
2222
///
23-
func isEmptyLine(at offset: Int) -> Bool {
23+
public func isEmptyLine(at offset: Int) -> Bool {
2424
guard let index = self.indexFromLocation(offset) else {
2525
return true
2626
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public class ElementNode: Node {
136136

137137
override func needsClosingParagraphSeparator() -> Bool {
138138
return (!hasChildren())
139-
&& (hasAttributes() || !isLastInTree())
139+
&& (canBeLastInTree() || !isLastInTree())
140140
&& (isBlockLevel() || hasRightBlockLevelSibling() || isLastInAncestorEndingInBlockLevelSeparation())
141141
}
142142

@@ -258,6 +258,14 @@ public class ElementNode: Node {
258258
return false
259259
}
260260

261+
/// Check if the node can be the last one in a tree
262+
///
263+
/// - Returns: Returns `true` if it can be the last one, false otherwise.
264+
///
265+
func canBeLastInTree() -> Bool {
266+
return hasAttributes() || type == .li
267+
}
268+
261269
/// Find out if this is a block-level element.
262270
///
263271
/// - Returns: `true` if this is a block-level element. `false` otherwise.

AztecTests/TextKit/TextViewTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,4 +1980,13 @@ class TextViewTests: XCTestCase {
19801980

19811981
XCTAssertEqual(output, expected)
19821982
}
1983+
1984+
/// This test makes sure that if an empty list is in the original HTML, it will still get output after our processing.
1985+
func testEmptyListsPersistsAfterAztec() {
1986+
let textView = TextViewStub(withHTML: "<ul><li></li></ul>")
1987+
1988+
let html = textView.getHTML(prettify: false)
1989+
1990+
XCTAssertEqual(html, "<ul><li></li></ul>")
1991+
}
19831992
}

0 commit comments

Comments
 (0)