Skip to content

Commit 1d16781

Browse files
authored
Make visitLineBreak return new line instead of space (#633) (#659)
* Make visitLineBreak return new line instead of space * Update test case for more human-readable
1 parent 055a3d9 commit 1d16781

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct RenderContentCompiler: MarkupVisitor {
275275
}
276276

277277
mutating func visitLineBreak(_ lineBreak: LineBreak) -> [RenderContent] {
278-
return [RenderInlineContent.text(" ")]
278+
return [RenderInlineContent.text("\n")]
279279
}
280280

281281
mutating func visitEmphasis(_ emphasis: Emphasis) -> [RenderContent] {

Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift

+65
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,69 @@ class RenderContentCompilerTests: XCTestCase {
131131
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [link]))
132132
}
133133
}
134+
135+
func testLineBreak() throws {
136+
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
137+
var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/path", fragment: nil, sourceLanguage: .swift))
138+
139+
let source = #"""
140+
Backslash before new line\
141+
is an explicit hard line break.
142+
143+
Two spaces before new line
144+
is a hard line break.
145+
146+
Paragraph can't end with hard line break.\
147+
148+
# Headings can't end with hard line break.\
149+
150+
Code blocks ignore\
151+
hard line breaks.
152+
153+
A single space before new line
154+
is a soft line break.
155+
"""#
156+
let document = Document(parsing: source)
157+
let expectedDump = #"""
158+
Document
159+
├─ Paragraph
160+
│ ├─ Text "Backslash before new line"
161+
│ ├─ LineBreak
162+
│ └─ Text "is an explicit hard line break."
163+
├─ Paragraph
164+
│ ├─ Text "Two spaces before new line"
165+
│ ├─ LineBreak
166+
│ └─ Text "is a hard line break."
167+
├─ Paragraph
168+
│ └─ Text "Paragraph can’t end with hard line break.\"
169+
├─ Heading level: 1
170+
│ └─ Text "Headings can’t end with hard line break.\"
171+
├─ CodeBlock language: none
172+
│ Code blocks ignore\
173+
│ hard line breaks.
174+
└─ Paragraph
175+
├─ Text "A single space before new line"
176+
├─ SoftBreak
177+
└─ Text "is a soft line break."
178+
"""#
179+
XCTAssertEqual(document.debugDescription(), expectedDump)
180+
let result = document.children.flatMap { compiler.visit($0) }
181+
XCTAssertEqual(result.count, 6)
182+
do {
183+
guard case let .paragraph(paragraph) = result[0] as? RenderBlockContent else {
184+
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)")
185+
return
186+
}
187+
let text = RenderInlineContent.text("\n")
188+
XCTAssertEqual(paragraph.inlineContent[1], text)
189+
}
190+
do {
191+
guard case let .paragraph(paragraph) = result[1] as? RenderBlockContent else {
192+
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)")
193+
return
194+
}
195+
let text = RenderInlineContent.text("\n")
196+
XCTAssertEqual(paragraph.inlineContent[1], text)
197+
}
198+
}
134199
}

0 commit comments

Comments
 (0)