Fix extra line breaks being inserted before lists

This commit is contained in:
Shadowfacts 2024-01-16 19:26:40 -05:00
parent a32b972201
commit 74baa2912f
2 changed files with 16 additions and 1 deletions

View File

@ -135,7 +135,7 @@ public struct AttributedStringConverter<Callbacks: HTMLConversionCallbacks> {
finishRun()
styleStack.append(.unorderedList)
case "li":
if str.length != 0 || !currentRun.isEmpty {
if !currentRun.isEmpty {
currentRun.append("\n")
}
let marker: String

View File

@ -319,4 +319,19 @@ final class AttributedStringConverterTests: XCTestCase {
XCTAssertEqual(convert("<p></p><blockquote><span>inside<br>quote</span></blockquote><span>after</span><p></p>"), result)
}
func testParagraphFollowedByList() {
let result = NSMutableAttributedString()
result.append(NSAttributedString(string: "a\n\n", attributes: [
.font: font,
.paragraphStyle: NSParagraphStyle.default,
.foregroundColor: color,
]))
result.append(NSAttributedString(string: "\t1.\tb", attributes: [
.font: font,
.paragraphStyle: listParagraphStyle,
.foregroundColor: color,
]))
XCTAssertEqual(convert("<p>a</p><ol><li>b</li></ol>"), result)
}
}