|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See https://swift.org/LICENSE.txt for license information |
| 8 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +*/ |
| 10 | + |
| 11 | +import Foundation |
| 12 | + |
| 13 | +/// A parsed Doxygen `\abstract` command. |
| 14 | +/// |
| 15 | +/// The Doxygen support in Swift-Markdown parses `\abstract` commands of the form |
| 16 | +/// `\abstract description`, where `description` continues until the next blank |
| 17 | +/// line or parsed command. |
| 18 | +/// |
| 19 | +/// ```markdown |
| 20 | +/// \abstract This object can give other objects in your program magical powers. |
| 21 | +/// ``` |
| 22 | +public struct DoxygenAbstract: BlockContainer { |
| 23 | + public var _data: _MarkupData |
| 24 | + |
| 25 | + init(_ raw: RawMarkup) throws { |
| 26 | + guard case .doxygenAbstract = raw.data else { |
| 27 | + throw RawMarkup.Error.concreteConversionError(from: raw, to: DoxygenAbstract.self) |
| 28 | + } |
| 29 | + let absoluteRaw = AbsoluteRawMarkup(markup: raw, metadata: MarkupMetadata(id: .newRoot(), indexInParent: 0)) |
| 30 | + self.init(_MarkupData(absoluteRaw)) |
| 31 | + } |
| 32 | + |
| 33 | + init(_ data: _MarkupData) { |
| 34 | + self._data = data |
| 35 | + } |
| 36 | + |
| 37 | + public func accept<V: MarkupVisitor>(_ visitor: inout V) -> V.Result { |
| 38 | + return visitor.visitDoxygenAbstract(self) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +public extension DoxygenAbstract { |
| 43 | + /// Create a new Doxygen abstract definition. |
| 44 | + /// |
| 45 | + /// - Parameter children: Block child elements. |
| 46 | + init<Children: Sequence>(children: Children) where Children.Element == BlockMarkup { |
| 47 | + try! self.init(.doxygenAbstract(parsedRange: nil, children.map({ $0.raw.markup }))) |
| 48 | + } |
| 49 | + |
| 50 | + /// Create a new Doxygen abstract definition. |
| 51 | + /// |
| 52 | + /// - Parameter children: Block child elements. |
| 53 | + init(children: BlockMarkup...) { |
| 54 | + self.init(children: children) |
| 55 | + } |
| 56 | +} |
| 57 | + |
0 commit comments