Skip to content

Commit 2f24da8

Browse files
committed
Adding support for abstract headerdoc tag so the methods or properties with abstract headerdoc tag retains documentation
1 parent 114f761 commit 2f24da8

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

Sources/Markdown/Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenAbstract.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Foundation
1717
/// line or parsed command.
1818
///
1919
/// ```markdown
20-
/// \discussion This object can give other objects in your program magical powers.
20+
/// \abstract This object can give other objects in your program magical powers.
2121
/// ```
2222
public struct DoxygenAbstract: BlockContainer {
2323
public var _data: _MarkupData
@@ -40,14 +40,14 @@ public struct DoxygenAbstract: BlockContainer {
4040
}
4141

4242
public extension DoxygenAbstract {
43-
/// Create a new Doxygen discussion definition.
43+
/// Create a new Doxygen abstract definition.
4444
///
4545
/// - Parameter children: Block child elements.
4646
init<Children: Sequence>(children: Children) where Children.Element == BlockMarkup {
4747
try! self.init(.doxygenAbstract(parsedRange: nil, children.map({ $0.raw.markup })))
4848
}
4949

50-
/// Create a new Doxygen discussion definition.
50+
/// Create a new Doxygen abstract definition.
5151
///
5252
/// - Parameter children: Block child elements.
5353
init(children: BlockMarkup...) {

Sources/Markdown/Markdown.docc/Markdown/DoxygenCommands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Doxygen commands are not parsed within code blocks or block directive content.
4444

4545
### Commands
4646

47+
- ``DoxygenAbstract``
4748
- ``DoxygenDiscussion``
4849
- ``DoxygenNote``
4950
- ``DoxygenParameter``

Sources/Markdown/Walker/Walkers/MarkupFormatter.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -1178,6 +1178,11 @@ public struct MarkupFormatter: MarkupWalker {
11781178
descendInto(doxygenDiscussion)
11791179
}
11801180

1181+
public mutating func visitDoxygenAbstract(_ doxygenAbstract: DoxygenAbstract) {
1182+
printDoxygenStart("abstract", for: doxygenAbstract)
1183+
descendInto(doxygenAbstract)
1184+
}
1185+
11811186
public mutating func visitDoxygenNote(_ doxygenNote: DoxygenNote) {
11821187
printDoxygenStart("note", for: doxygenNote)
11831188
descendInto(doxygenNote)
@@ -1194,4 +1199,5 @@ public struct MarkupFormatter: MarkupWalker {
11941199
printDoxygenStart("returns", for: doxygenReturns)
11951200
descendInto(doxygenReturns)
11961201
}
1202+
11971203
}

Tests/MarkdownTests/Parsing/DoxygenCommandParserTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ class DoxygenCommandParserTests: XCTestCase {
469469
let expectedDump = #"""
470470
Document
471471
├─ BlockDirective name: "method"
472-
├─ BlockDirective name: "abstract"
472+
├─ DoxygenAbstract
473+
│ └─ Paragraph
474+
│ └─ Text "Some brief description of this method"
473475
├─ DoxygenParameter parameter: number
474476
│ └─ Paragraph
475477
│ └─ Text "Some description of the “number” parameter"

Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ class MarkupFormatterSingleElementTests: XCTestCase {
301301
XCTAssertEqual(expectedAt, printedAt)
302302
}
303303

304+
func testPrintDoxygenAbstract() {
305+
let expected = #"\abstract Another thing."#
306+
let printed = DoxygenAbstract(children: Paragraph(Text("Another thing."))).format()
307+
print (printed)
308+
XCTAssertEqual(expected, printed)
309+
}
310+
311+
func testPrintDoxygenAbstractMultiline() {
312+
let expected = #"""
313+
\abstract Another thing.
314+
This is an extended abstract.
315+
"""#
316+
let printed = DoxygenAbstract(children: Paragraph(
317+
Text("Another thing."),
318+
SoftBreak(),
319+
Text("This is an extended abstract.")
320+
)).format()
321+
XCTAssertEqual(expected, printed)
322+
}
323+
304324
func testPrintDoxygenDiscussion() {
305325
let expected = #"\discussion Another thing."#
306326
let printed = DoxygenDiscussion(children: Paragraph(Text("Another thing."))).format()

0 commit comments

Comments
 (0)