diff --git a/Sources/HTMLStreamer/BlockState.swift b/Sources/HTMLStreamer/BlockState.swift index c409adc..b8fb124 100644 --- a/Sources/HTMLStreamer/BlockState.swift +++ b/Sources/HTMLStreamer/BlockState.swift @@ -19,7 +19,15 @@ import Foundation */ struct BlockStateMachine { + #if false + var blockState: BlockState = .start { + didSet { + print("\(oldValue) -> \(blockState)") + } + } + #else var blockState: BlockState = .start + #endif let blockBreak: String let lineBreak: String let listIndentForContentOutsideItem: String @@ -70,7 +78,8 @@ extension BlockStateMachine { blockState = .preformattedEmptyBlock(depth: depth) case .afterPreStartTagWithLeadingWhitespace(let depth): blockState = .preformattedEmptyBlockWithLeadingWhitespace(depth: depth) - case .preformattedNonEmptyBlockWithTrailingWhitespace(depth: _): + case .preformattedNonEmptyBlockWithTrailingWhitespace(let depth): + blockState = .preformattedEmptyBlockWithLeadingWhitespace(depth: depth) temporaryBuffer.append(blockBreak) case .preformattedEmptyBlockWithLeadingWhitespace(depth: _): break diff --git a/Tests/HTMLStreamerTests/AttributedStringConverterTests.swift b/Tests/HTMLStreamerTests/AttributedStringConverterTests.swift index 0fef3ce..87f1856 100644 --- a/Tests/HTMLStreamerTests/AttributedStringConverterTests.swift +++ b/Tests/HTMLStreamerTests/AttributedStringConverterTests.swift @@ -687,5 +687,13 @@ final class AttributedStringConverterTests: XCTestCase { XCTAssertEqual(convert("

a


b

c

"), result2) } + func testWhitespaceAtEndOfPre() { + let result = NSAttributedString(string: "a", attributes: [ + .font: monospaceFont, + .paragraphStyle: NSParagraphStyle.default, + .foregroundColor: color, + ]) + XCTAssertEqual(convert("
a 
"), result) + } }