-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into allow-separate-strong-emphasis-marker
- Loading branch information
Showing
25 changed files
with
1,092 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Sample document | ||
|
||
This is a *sample document*. | ||
|
||
<!-- Copyright (c) 2022 Apple Inc and the Swift Project authors. All Rights Reserved. --> |
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
78 changes: 78 additions & 0 deletions
78
Sources/Markdown/Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenParameter.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,78 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2023 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 `\param` command. | ||
/// | ||
/// The Doxygen support in Swift-Markdown parses `\param` commands of the form | ||
/// `\param name description`, where `description` extends until the next blank line or the next | ||
/// parsed command. For example, the following input will return two `DoxygenParam` instances: | ||
/// | ||
/// ```markdown | ||
/// \param coordinate The coordinate used to center the transformation. | ||
/// \param matrix The transformation matrix that describes the transformation. | ||
/// For more information about transformation matrices, refer to the Transformation | ||
/// documentation. | ||
/// ``` | ||
public struct DoxygenParameter: BlockContainer { | ||
public var _data: _MarkupData | ||
|
||
init(_ raw: RawMarkup) throws { | ||
guard case .doxygenParam = raw.data else { | ||
throw RawMarkup.Error.concreteConversionError(from: raw, to: DoxygenParameter.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.visitDoxygenParameter(self) | ||
} | ||
} | ||
|
||
public extension DoxygenParameter { | ||
/// Create a new Doxygen parameter definition. | ||
/// | ||
/// - Parameter name: The name of the parameter being described. | ||
/// - Parameter children: Block child elements. | ||
init<Children: Sequence>(name: String, children: Children) where Children.Element == BlockMarkup { | ||
try! self.init(.doxygenParam(name: name, parsedRange: nil, children.map({ $0.raw.markup }))) | ||
} | ||
|
||
/// Create a new Doxygen parameter definition. | ||
/// | ||
/// - Parameter name: The name of the parameter being described. | ||
/// - Parameter children: Block child elements. | ||
init(name: String, children: BlockMarkup...) { | ||
self.init(name: name, children: children) | ||
} | ||
|
||
/// The name of the parameter being described. | ||
var name: String { | ||
get { | ||
guard case let .doxygenParam(name) = _data.raw.markup.data else { | ||
fatalError("\(self) markup wrapped unexpected \(_data.raw)") | ||
} | ||
return name | ||
} | ||
set { | ||
_data = _data.replacingSelf(.doxygenParam( | ||
name: newValue, | ||
parsedRange: nil, | ||
_data.raw.markup.copyChildren() | ||
)) | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/Markdown/Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenReturns.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,58 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2023 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 `\returns`, `\return`, or `\result` command. | ||
/// | ||
/// The Doxygen support in Swift-Markdown parses `\returns` commands of the form | ||
/// `\returns description`, where `description` continues until the next blank line or parsed | ||
/// command. The commands `\return` and `\result` are also accepted, with the same format. | ||
/// | ||
/// ```markdown | ||
/// \returns A freshly-created object. | ||
/// ``` | ||
public struct DoxygenReturns: BlockContainer { | ||
public var _data: _MarkupData | ||
|
||
init(_ raw: RawMarkup) throws { | ||
guard case .doxygenReturns = raw.data else { | ||
throw RawMarkup.Error.concreteConversionError(from: raw, to: DoxygenReturns.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.visitDoxygenReturns(self) | ||
} | ||
} | ||
|
||
public extension DoxygenReturns { | ||
/// Create a new Doxygen parameter definition. | ||
/// | ||
/// - Parameter name: The name of the parameter being described. | ||
/// - Parameter children: Block child elements. | ||
init<Children: Sequence>(children: Children) where Children.Element == BlockMarkup { | ||
try! self.init(.doxygenReturns(parsedRange: nil, children.map({ $0.raw.markup }))) | ||
} | ||
|
||
/// Create a new Doxygen parameter definition. | ||
/// | ||
/// - Parameter name: The name of the parameter being described. | ||
/// - 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
50 changes: 50 additions & 0 deletions
50
Sources/Markdown/Markdown.docc/Markdown/DoxygenCommands.md
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,50 @@ | ||
# Doxygen Commands | ||
|
||
Include a limited set of Doxygen commands in parsed Markdown. | ||
|
||
Swift Markdown includes an option to parse a limited set of Doxygen commands, to facilitate | ||
transitioning from a different Markdown parser. To include these commands in the output, include | ||
the options ``ParseOptions/parseBlockDirectives`` and ``ParseOptions/parseMinimalDoxygen`` when | ||
parsing a ``Document``. In the resulting document, parsed Doxygen commands appear as regular | ||
``Markup`` types in the hierarchy. | ||
|
||
## Parsing Strategy | ||
|
||
Doxygen commands are written by using either a backslash (`\`) or an at-sign (`@`) character, | ||
followed by the name of the command. Any parameters are then parsed as whitespace-separated words, | ||
then a "description" argument is taken from the remainder of the line, as well as all lines | ||
immediately after the command, until the parser sees a blank line, another Doxygen command, or a | ||
block directive. The description is then parsed for regular Markdown formatting, which is then | ||
stored as the children of the command type. For example, with Doxygen parsing turned on, the | ||
following document will parse three separate commands and one block directive: | ||
|
||
```markdown | ||
\param thing The thing. | ||
This is the thing that is modified. | ||
\param otherThing The other thing. | ||
|
||
\returns A thing that has been modified. | ||
@Comment { | ||
This is not part of the `\returns` command. | ||
} | ||
``` | ||
|
||
Trailing lines in a command's description are allowed to be indented relative to the command. For | ||
example, the description below is parsed as a paragraph, not a code block: | ||
|
||
```markdown | ||
\param thing | ||
The thing. | ||
This is the thing that is modified. | ||
``` | ||
|
||
Doxygen commands are not parsed within code blocks or block directive content. | ||
|
||
## Topics | ||
|
||
### Commands | ||
|
||
- ``DoxygenParam`` | ||
- ``DoxygenReturns`` | ||
|
||
<!-- Copyright (c) 2023 Apple Inc and the Swift Project authors. All Rights Reserved. --> |
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
Oops, something went wrong.