Fix error when whitespace occurs at end of <pre>

I had the state machine correct and made a mistake when converting it to code :/
This commit is contained in:
Shadowfacts 2024-07-08 21:12:44 -07:00
parent a93a53e8d3
commit e01664565f
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -687,5 +687,13 @@ final class AttributedStringConverterTests: XCTestCase {
XCTAssertEqual(convert("<p>a</p><p><br>b</p><p>c</p>"), result2)
}
func testWhitespaceAtEndOfPre() {
let result = NSAttributedString(string: "a", attributes: [
.font: monospaceFont,
.paragraphStyle: NSParagraphStyle.default,
.foregroundColor: color,
])
XCTAssertEqual(convert("<pre>a </pre>"), result)
}
}