diff --git a/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift b/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift
index 2b218fb..ad528c6 100644
--- a/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift
+++ b/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift
@@ -16,6 +16,8 @@ internal extension StringProtocol {
return "<"
case ">":
return ">"
+ case "\n":
+ return "
"
default:
return String(character)
}
diff --git a/Tests/SplashTests/Tests/HTMLOutputFormatTests.swift b/Tests/SplashTests/Tests/HTMLOutputFormatTests.swift
index a317449..f720ec0 100644
--- a/Tests/SplashTests/Tests/HTMLOutputFormatTests.swift
+++ b/Tests/SplashTests/Tests/HTMLOutputFormatTests.swift
@@ -39,4 +39,16 @@ final class HTMLOutputFormatTests: XCTestCase {
""")
}
+
+ func testEncodingNewlinesWithBreakTag() {
+ let html = highlighter.highlight("""
+ // comment line 1
+ // comment line 2
+ func expressTheCommentAbove()
+ """)
+
+ XCTAssertEqual(html, """
+ \nfunc expressTheCommentAbove()
+ """)
+ }
}