Skip to content

Commit 679b531

Browse files
authored
Revert "Add preceding newlines before Doxygen commands" (#248)
* Revert "Control Doxygen commands preceding newline by formatter options" This reverts commit 3bc74b6. * Revert "Add preceding newlines before Doxygen commands" This reverts commit 08d2627.
1 parent 3bc74b6 commit 679b531

File tree

2 files changed

+1
-102
lines changed

2 files changed

+1
-102
lines changed

Sources/Markdown/Walker/Walkers/MarkupFormatter.swift

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ fileprivate extension Markup {
3333
}
3434
return nil
3535
}
36-
37-
/// Previous sibling of this element in its parent, or `nil` if it's the first child.
38-
var previousSibling: Markup? {
39-
guard let parent, indexInParent > 0 else {
40-
return nil
41-
}
42-
43-
return parent.child(at: indexInParent - 1)
44-
}
45-
46-
/// Whether this element is a Doxygen command.
47-
var isDoxygenCommand: Bool {
48-
return self is DoxygenDiscussion || self is DoxygenNote || self is DoxygenAbstract
49-
|| self is DoxygenParameter || self is DoxygenReturns
50-
}
5136
}
5237

5338
fileprivate extension String {
@@ -254,15 +239,6 @@ public struct MarkupFormatter: MarkupWalker {
254239
case at = "@"
255240
}
256241

257-
/// The spacing to use when formatting adjacent Doxygen commands.
258-
public enum AdjacentDoxygenCommandsSpacing: String, CaseIterable {
259-
/// Separate adjacent Doxygen commands with a single newline.
260-
case singleNewline = "single-newline"
261-
262-
/// Keep a blank line between adjacent Doxygen commands creating separate paragraphs.
263-
case separateParagraphs = "separate-paragraphs"
264-
}
265-
266242
// MARK: Option Properties
267243

268244
var orderedListNumerals: OrderedListNumerals
@@ -277,7 +253,6 @@ public struct MarkupFormatter: MarkupWalker {
277253
var preferredLineLimit: PreferredLineLimit?
278254
var customLinePrefix: String
279255
var doxygenCommandPrefix: DoxygenCommandPrefix
280-
var adjacentDoxygenCommandsSpacing: AdjacentDoxygenCommandsSpacing
281256

282257
/**
283258
Create a set of formatting options to use when printing an element.
@@ -295,7 +270,6 @@ public struct MarkupFormatter: MarkupWalker {
295270
- preferredLineLimit: The preferred maximum line length and method for splitting ``Text`` elements in an attempt to maintain that line length.
296271
- customLinePrefix: An addition prefix to print at the start of each line, useful for adding documentation comment markers.
297272
- doxygenCommandPrefix: The command command prefix, which defaults to ``DoxygenCommandPrefix/backslash``.
298-
- adjacentDoxygenCommandsSpacing: The spacing to use when formatting adjacent Doxygen commands.
299273
*/
300274
public init(unorderedListMarker: UnorderedListMarker = .dash,
301275
orderedListNumerals: OrderedListNumerals = .allSame(1),
@@ -308,8 +282,7 @@ public struct MarkupFormatter: MarkupWalker {
308282
preferredHeadingStyle: PreferredHeadingStyle = .atx,
309283
preferredLineLimit: PreferredLineLimit? = nil,
310284
customLinePrefix: String = "",
311-
doxygenCommandPrefix: DoxygenCommandPrefix = .backslash,
312-
adjacentDoxygenCommandsSpacing: AdjacentDoxygenCommandsSpacing = .singleNewline) {
285+
doxygenCommandPrefix: DoxygenCommandPrefix = .backslash) {
313286
self.unorderedListMarker = unorderedListMarker
314287
self.orderedListNumerals = orderedListNumerals
315288
self.useCodeFence = useCodeFence
@@ -324,7 +297,6 @@ public struct MarkupFormatter: MarkupWalker {
324297
self.thematicBreakLength = max(3, thematicBreakLength)
325298
self.customLinePrefix = customLinePrefix
326299
self.doxygenCommandPrefix = doxygenCommandPrefix
327-
self.adjacentDoxygenCommandsSpacing = adjacentDoxygenCommandsSpacing
328300
}
329301

330302
/// The default set of formatting options.
@@ -1201,47 +1173,28 @@ public struct MarkupFormatter: MarkupWalker {
12011173
print(formattingOptions.doxygenCommandPrefix.rawValue + name + " ", for: element)
12021174
}
12031175

1204-
private mutating func ensureDoxygenCommandPrecedingNewline(for element: Markup) {
1205-
guard let previousSibling = element.previousSibling else {
1206-
return
1207-
}
1208-
1209-
guard formattingOptions.adjacentDoxygenCommandsSpacing == .singleNewline else {
1210-
ensurePrecedingNewlineCount(atLeast: 2)
1211-
return
1212-
}
1213-
1214-
let newlineCount = previousSibling.isDoxygenCommand ? 1 : 2
1215-
ensurePrecedingNewlineCount(atLeast: newlineCount)
1216-
}
1217-
12181176
public mutating func visitDoxygenDiscussion(_ doxygenDiscussion: DoxygenDiscussion) {
1219-
ensureDoxygenCommandPrecedingNewline(for: doxygenDiscussion)
12201177
printDoxygenStart("discussion", for: doxygenDiscussion)
12211178
descendInto(doxygenDiscussion)
12221179
}
12231180

12241181
public mutating func visitDoxygenAbstract(_ doxygenAbstract: DoxygenAbstract) {
1225-
ensureDoxygenCommandPrecedingNewline(for: doxygenAbstract)
12261182
printDoxygenStart("abstract", for: doxygenAbstract)
12271183
descendInto(doxygenAbstract)
12281184
}
12291185

12301186
public mutating func visitDoxygenNote(_ doxygenNote: DoxygenNote) {
1231-
ensureDoxygenCommandPrecedingNewline(for: doxygenNote)
12321187
printDoxygenStart("note", for: doxygenNote)
12331188
descendInto(doxygenNote)
12341189
}
12351190

12361191
public mutating func visitDoxygenParameter(_ doxygenParam: DoxygenParameter) {
1237-
ensureDoxygenCommandPrecedingNewline(for: doxygenParam)
12381192
printDoxygenStart("param", for: doxygenParam)
12391193
print("\(doxygenParam.name) ", for: doxygenParam)
12401194
descendInto(doxygenParam)
12411195
}
12421196

12431197
public mutating func visitDoxygenReturns(_ doxygenReturns: DoxygenReturns) {
1244-
ensureDoxygenCommandPrecedingNewline(for: doxygenReturns)
12451198
// FIXME: store the actual command name used in the original markup
12461199
printDoxygenStart("returns", for: doxygenReturns)
12471200
descendInto(doxygenReturns)

Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,58 +1626,4 @@ class MarkupFormatterMixedContentTests: XCTestCase {
16261626
]
16271627
zip(expected, printed).forEach { XCTAssertEqual($0, $1) }
16281628
}
1629-
1630-
func testDoxygenCommandsPrecedingNewlinesWithSingleNewline() {
1631-
let expected = #"""
1632-
Does something.
1633-
1634-
\abstract abstract
1635-
\param x first param
1636-
\returns result
1637-
\note note
1638-
\discussion discussion
1639-
"""#
1640-
1641-
let formattingOptions = MarkupFormatter.Options(
1642-
adjacentDoxygenCommandsSpacing: .singleNewline)
1643-
let printed = Document(
1644-
Paragraph(Text("Does something.")),
1645-
DoxygenAbstract(children: Paragraph(Text("abstract"))),
1646-
DoxygenParameter(name: "x", children: Paragraph(Text("first param"))),
1647-
DoxygenReturns(children: Paragraph(Text("result"))),
1648-
DoxygenNote(children: Paragraph(Text("note"))),
1649-
DoxygenDiscussion(children: Paragraph(Text("discussion")))
1650-
).format(options: formattingOptions)
1651-
1652-
XCTAssertEqual(expected, printed)
1653-
}
1654-
1655-
func testDoxygenCommandsPrecedingNewlinesAsSeparateParagraphs() {
1656-
let expected = #"""
1657-
Does something.
1658-
1659-
\abstract abstract
1660-
1661-
\param x first param
1662-
1663-
\returns result
1664-
1665-
\note note
1666-
1667-
\discussion discussion
1668-
"""#
1669-
1670-
let formattingOptions = MarkupFormatter.Options(
1671-
adjacentDoxygenCommandsSpacing: .separateParagraphs)
1672-
let printed = Document(
1673-
Paragraph(Text("Does something.")),
1674-
DoxygenAbstract(children: Paragraph(Text("abstract"))),
1675-
DoxygenParameter(name: "x", children: Paragraph(Text("first param"))),
1676-
DoxygenReturns(children: Paragraph(Text("result"))),
1677-
DoxygenNote(children: Paragraph(Text("note"))),
1678-
DoxygenDiscussion(children: Paragraph(Text("discussion")))
1679-
).format(options: formattingOptions)
1680-
1681-
XCTAssertEqual(expected, printed)
1682-
}
16831629
}

0 commit comments

Comments
 (0)