Skip to content

Commit 77b47ba

Browse files
author
ActuallyTaylor
committed
Fixed leading whitespace in #text
1 parent 36075cc commit 77b47ba

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Sources/SwiftHTMLtoMarkdown/MastodonHTML.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class MastodonHTML: HTML {
4949
markdown += "(\(href))"
5050
return
5151
} else if node.nodeName() == "#text" {
52-
markdown += node.description
52+
markdown += node.description.trimmingCharacters(in: .newlines)
5353
}
5454

5555
for node in node.getChildNodes() {

Tests/SwiftHTMLtoMarkdownTests/SwiftHTMLtoMarkdownTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ final class SwiftHTMLtoMarkdownTests: XCTestCase {
2424
XCTAssertTrue(markdown == correctOutput)
2525
}
2626

27+
func testMastodonHTMLSingleLine() throws {
28+
let raw = "This is a test"
29+
let correctOutput = "This is a test"
30+
var document = MastodonHTML(rawHTML: raw)
31+
try document.parse()
32+
33+
let markdown = try document.asMarkdown()
34+
print(markdown)
35+
XCTAssertTrue(markdown == correctOutput)
36+
}
2737
func testBasicHTML() throws {
2838
let raw = """
2939
<h1>Heading level 1</h1><h2>Heading level 2</h2>

0 commit comments

Comments
 (0)