Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,9 @@ public enum RenderBlockContent: Equatable {

/// A type the describes an aside style.
public struct AsideStyle: Codable, Equatable {
private static let specialDisplayNames: [String: String] = [
"nonmutatingvariant": "Non-Mutating Variant",
"mutatingvariant": "Mutating Variant",
"todo": "To Do",
]
private static let knownDisplayNames: [String: String] = Dictionary(
uniqueKeysWithValues: Markdown.Aside.Kind.allCases.map { ($0.rawValue.lowercased(), $0.displayName) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moves ownership of the displayName over to Swift-Markdown where the existing ownership of asides is. Moving forward, we'll be able to add new supported asides with a single PR.

A bit of a discussion about this here: swiftlang/swift-markdown#96 (comment)

)

/// Returns a Boolean value indicating whether two aside styles are equal.
///
Expand All @@ -317,7 +315,7 @@ public enum RenderBlockContent: Equatable {

/// The heading text to use when rendering this style of aside.
public var displayName: String {
if let value = Self.specialDisplayNames[rawValue.lowercased()] {
if let value = Self.knownDisplayNames[rawValue.lowercased()] {
return value
} else if rawValue.contains(where: \.isUppercase) {
// If any character is upper-cased, assume the content has
Expand Down Expand Up @@ -363,7 +361,7 @@ public enum RenderBlockContent: Equatable {
/// Creates an aside style with the specified display name.
/// - Parameter displayName: The heading text to use when rendering this style of aside.
public init(displayName: String) {
self.rawValue = Self.specialDisplayNames.first(where: { $0.value == displayName })?.key ?? displayName
self.rawValue = Self.knownDisplayNames.first(where: { $0.value == displayName })?.key ?? displayName
}

/// Encodes the aside style into the specified encoder.
Expand Down
6 changes: 6 additions & 0 deletions Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,8 @@ Document
.aside(.init(style: .init(rawValue: "Since"), content: [.paragraph(.init(inlineContent: [.text("The beginning of time.")]))])),
.aside(.init(style: .init(rawValue: "Todo"), content: [.paragraph(.init(inlineContent: [.text("This needs work.")]))])),
.aside(.init(style: .init(rawValue: "Version"), content: [.paragraph(.init(inlineContent: [.text("3.1.4")]))])),
.aside(.init(style: .init(rawValue: "SeeAlso"), content: [.paragraph(.init(inlineContent: [.text("This other thing.")]))])),
.aside(.init(style: .init(rawValue: "SeeAlso"), content: [.paragraph(.init(inlineContent: [.text("And this other thing.")]))])),
.aside(.init(style: .init(rawValue: "Throws"), content: [.paragraph(.init(inlineContent: [.text("A serious error.")]))])),
]

Expand Down Expand Up @@ -2996,6 +2998,10 @@ Document
"content": [{"type":"paragraph", "inlineContent":[{"type":"text", "text":"This needs work."}]}]},
{"type":"aside", "style":"note", "name":"Version",
"content": [{"type":"paragraph", "inlineContent":[{"type":"text", "text":"3.1.4"}]}]},
{"type":"aside", "style":"note", "name":"See Also",
"content": [{"type":"paragraph", "inlineContent":[{"type":"text", "text":"This other thing."}]}]},
{"type":"aside", "style":"note", "name":"See Also",
"content": [{"type":"paragraph", "inlineContent":[{"type":"text", "text":"And this other thing."}]}]},
{"type":"aside", "style":"note", "name":"Throws",
"content": [{"type":"paragraph", "inlineContent":[{"type":"text", "text":"A serious error."}]}]}
]
Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftDocCTests/Test Resources/Asides.symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@
{
"text": ""
},
{
"text": "> seealso: This other thing."
},
{
"text": ""
},
{
"text": "> SeeAlso: And this other thing."
},
{
"text": ""
},
{
"text": "> Throws: A serious error."
}
Expand Down Expand Up @@ -421,6 +433,18 @@
{
"text": ""
},
{
"text": "- SeeAlso: This other thing."
},
{
"text": ""
},
{
"text": "- seealso: And this other thing."
},
{
"text": ""
},
{
"text": "- Throws: A serious error."
}
Expand Down