From fdf392401d323b575316feb3f5fa173d811ecde0 Mon Sep 17 00:00:00 2001 From: Brian Cordan Young Date: Sun, 26 Nov 2023 16:39:52 -0800 Subject: [PATCH 1/2] Encode newlines with break tag --- Sources/Splash/Extensions/Strings/String+HTMLEntities.swift | 2 ++ 1 file changed, 2 insertions(+) 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) } From 7b3189260a834061aa6805fc4a80a72566f0a53a Mon Sep 17 00:00:00 2001 From: Brian Cordan Young Date: Sun, 26 Nov 2023 21:35:55 -0800 Subject: [PATCH 2/2] Test newline encoding --- Tests/SplashTests/Tests/HTMLOutputFormatTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 { // Hey I'm a comment! """) } + + func testEncodingNewlinesWithBreakTag() { + let html = highlighter.highlight(""" + // comment line 1 + // comment line 2 + func expressTheCommentAbove() + """) + + XCTAssertEqual(html, """ + // comment line 1
// comment line 2
\nfunc expressTheCommentAbove() + """) + } }