-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Doxygen discussion/note tags (#159)
* Fix DoxygenReturns doc comments * Add support for parsing Doxygen \discussion and \note block-level commands * Add some tests * Update CMakeLists.txt
- Loading branch information
Showing
9 changed files
with
214 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Sources/Markdown/Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenDiscussion.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// A parsed Doxygen `\discussion` command. | ||
/// | ||
/// The Doxygen support in Swift-Markdown parses `\discussion` commands of the form | ||
/// `\discussion description`, where `description` continues until the next blank | ||
/// line or parsed command. | ||
/// | ||
/// ```markdown | ||
/// \discussion This object can give other objects in your program magical powers. | ||
/// ``` | ||
public struct DoxygenDiscussion: BlockContainer { | ||
public var _data: _MarkupData | ||
|
||
init(_ raw: RawMarkup) throws { | ||
guard case .doxygenDiscussion = raw.data else { | ||
throw RawMarkup.Error.concreteConversionError(from: raw, to: DoxygenDiscussion.self) | ||
} | ||
let absoluteRaw = AbsoluteRawMarkup(markup: raw, metadata: MarkupMetadata(id: .newRoot(), indexInParent: 0)) | ||
self.init(_MarkupData(absoluteRaw)) | ||
} | ||
|
||
init(_ data: _MarkupData) { | ||
self._data = data | ||
} | ||
|
||
public func accept<V: MarkupVisitor>(_ visitor: inout V) -> V.Result { | ||
return visitor.visitDoxygenDiscussion(self) | ||
} | ||
} | ||
|
||
public extension DoxygenDiscussion { | ||
/// Create a new Doxygen discussion definition. | ||
/// | ||
/// - Parameter children: Block child elements. | ||
init<Children: Sequence>(children: Children) where Children.Element == BlockMarkup { | ||
try! self.init(.doxygenDiscussion(parsedRange: nil, children.map({ $0.raw.markup }))) | ||
} | ||
|
||
/// Create a new Doxygen discussion definition. | ||
/// | ||
/// - Parameter children: Block child elements. | ||
init(children: BlockMarkup...) { | ||
self.init(children: children) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Sources/Markdown/Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenNote.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// A parsed Doxygen `\note` command. | ||
/// | ||
/// The Doxygen support in Swift-Markdown parses `\note` commands of the form | ||
/// `\note description`, where `description` continues until the next blank | ||
/// line or parsed command. | ||
/// | ||
/// ```markdown | ||
/// \note This method is only meant to be called an odd number of times. | ||
/// ``` | ||
public struct DoxygenNote: BlockContainer { | ||
public var _data: _MarkupData | ||
|
||
init(_ raw: RawMarkup) throws { | ||
guard case .doxygenNote = raw.data else { | ||
throw RawMarkup.Error.concreteConversionError(from: raw, to: DoxygenNote.self) | ||
} | ||
let absoluteRaw = AbsoluteRawMarkup(markup: raw, metadata: MarkupMetadata(id: .newRoot(), indexInParent: 0)) | ||
self.init(_MarkupData(absoluteRaw)) | ||
} | ||
|
||
init(_ data: _MarkupData) { | ||
self._data = data | ||
} | ||
|
||
public func accept<V: MarkupVisitor>(_ visitor: inout V) -> V.Result { | ||
return visitor.visitDoxygenNote(self) | ||
} | ||
} | ||
|
||
public extension DoxygenNote { | ||
/// Create a new Doxygen note definition. | ||
/// | ||
/// - Parameter children: Block child elements. | ||
init<Children: Sequence>(children: Children) where Children.Element == BlockMarkup { | ||
try! self.init(.doxygenNote(parsedRange: nil, children.map({ $0.raw.markup }))) | ||
} | ||
|
||
/// Create a new Doxygen note definition. | ||
/// | ||
/// - Parameter children: Block child elements. | ||
init(children: BlockMarkup...) { | ||
self.init(children: children) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters