Skip to content

Commit 52a75b8

Browse files
committed
Add preceding newlines before Doxygen commands
1 parent c281baa commit 52a75b8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Sources/Markdown/Walker/Walkers/MarkupFormatter.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,27 +1174,47 @@ public struct MarkupFormatter: MarkupWalker {
11741174
}
11751175

11761176
public mutating func visitDoxygenDiscussion(_ doxygenDiscussion: DoxygenDiscussion) {
1177+
if doxygenDiscussion.indexInParent > 0 {
1178+
ensurePrecedingNewlineCount(atLeast: 2)
1179+
}
1180+
11771181
printDoxygenStart("discussion", for: doxygenDiscussion)
11781182
descendInto(doxygenDiscussion)
11791183
}
11801184

11811185
public mutating func visitDoxygenAbstract(_ doxygenAbstract: DoxygenAbstract) {
1186+
if doxygenAbstract.indexInParent > 0 {
1187+
ensurePrecedingNewlineCount(atLeast: 2)
1188+
}
1189+
11821190
printDoxygenStart("abstract", for: doxygenAbstract)
11831191
descendInto(doxygenAbstract)
11841192
}
11851193

11861194
public mutating func visitDoxygenNote(_ doxygenNote: DoxygenNote) {
1195+
if doxygenNote.indexInParent > 0 {
1196+
ensurePrecedingNewlineCount(atLeast: 2)
1197+
}
1198+
11871199
printDoxygenStart("note", for: doxygenNote)
11881200
descendInto(doxygenNote)
11891201
}
11901202

11911203
public mutating func visitDoxygenParameter(_ doxygenParam: DoxygenParameter) {
1204+
if doxygenParam.indexInParent > 0 {
1205+
ensurePrecedingNewlineCount(atLeast: 2)
1206+
}
1207+
11921208
printDoxygenStart("param", for: doxygenParam)
11931209
print("\(doxygenParam.name) ", for: doxygenParam)
11941210
descendInto(doxygenParam)
11951211
}
11961212

11971213
public mutating func visitDoxygenReturns(_ doxygenReturns: DoxygenReturns) {
1214+
if doxygenReturns.indexInParent > 0 {
1215+
ensurePrecedingNewlineCount(atLeast: 2)
1216+
}
1217+
11981218
// FIXME: store the actual command name used in the original markup
11991219
printDoxygenStart("returns", for: doxygenReturns)
12001220
descendInto(doxygenReturns)

Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,4 +1626,31 @@ class MarkupFormatterMixedContentTests: XCTestCase {
16261626
]
16271627
zip(expected, printed).forEach { XCTAssertEqual($0, $1) }
16281628
}
1629+
1630+
func testDoxygenCommandsWithPrecedingNewlines() {
1631+
let expected = #"""
1632+
Does something.
1633+
1634+
\abstract abstract
1635+
1636+
\param x first param
1637+
1638+
\returns result
1639+
1640+
\note note
1641+
1642+
\discussion discussion
1643+
"""#
1644+
1645+
let printed = Document(
1646+
Paragraph(Text("Does something.")),
1647+
DoxygenAbstract(children: Paragraph(Text("abstract"))),
1648+
DoxygenParameter(name: "x", children: Paragraph(Text("first param"))),
1649+
DoxygenReturns(children: Paragraph(Text("result"))),
1650+
DoxygenNote(children: Paragraph(Text("note"))),
1651+
DoxygenDiscussion(children: Paragraph(Text("discussion")))
1652+
).format()
1653+
1654+
XCTAssertEqual(expected, printed)
1655+
}
16291656
}

0 commit comments

Comments
 (0)