Skip to content

Commit

Permalink
HTML: Treat comments as self-closing tags (#10)
Browse files Browse the repository at this point in the history
This patch makes Ink parse HTML comments correctly, by treating them as
self-closing tags, rather than as opening ones (which would cause all
subsequent text to be parsed as plain HTML).
  • Loading branch information
JohnSundell committed Nov 28, 2019
1 parent e2f76b1 commit a4f0c8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Ink/Internal/HTML.swift
Expand Up @@ -74,7 +74,7 @@ private extension Reader {
return (name.dropLast(), true)
}

return (name, suffix.last == "/")
return (name, suffix.last == "/" || name == "!--")
}

advanceIndex()
Expand Down
13 changes: 12 additions & 1 deletion Tests/InkTests/HTMLTests.swift
Expand Up @@ -93,6 +93,16 @@ final class HTMLTests: XCTestCase {

XCTAssertEqual(html, "<p>Hello</p><br/><p>World</p>")
}

func testHTMLComment() {
let html = MarkdownParser().html(from: """
Hello
<!-- Comment -->
World
""")

XCTAssertEqual(html, "<p>Hello</p><!-- Comment --><p>World</p>")
}
}

extension HTMLTests {
Expand All @@ -107,7 +117,8 @@ extension HTMLTests {
("testInlineParagraphTagEndingCurrentParagraph", testInlineParagraphTagEndingCurrentParagraph),
("testTopLevelSelfClosingHTMLElement", testTopLevelSelfClosingHTMLElement),
("testInlineSelfClosingHTMLElement", testInlineSelfClosingHTMLElement),
("testTopLevelHTMLLineBreak", testTopLevelHTMLLineBreak)
("testTopLevelHTMLLineBreak", testTopLevelHTMLLineBreak),
("testHTMLComment", testHTMLComment)
]
}
}

0 comments on commit a4f0c8d

Please sign in to comment.