-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authoring support for the
@PageColor
directive
Adds a new `@PageColor` metadata directive that allows for customizing the color used to represent a given page. `@PageColor` gives authors control over the color used when rendering a page – initially this will affect the background color Swift-DocC-Render uses in the page's introduction (hero) section. Example: # What's New in SlothCreator @metadata { @PageColor(blue) } ![A sloth on a tree wearing a fedora.](sloth-fedora) Let's check out what's new in SlothCreator! ... Details: `@PageColor` accepts the following parameters: - `color`: An unnamed parameter that accepts one of the following: - `blue`: A context-dependent blue color. - `gray`: A context-dependent gray color. - `green`: A context-dependent orange color. - `orange`: A context-dependent orange color. - `purple`: A context-dependent purple color. - `red`: A context-dependent red color. - `yellow`: A context-dependent yellow color. `@PageColor` is described on the Swift forums here: https://forums.swift.org/t/support-for-customizing-a-page-s-accent-color-in-swift-docc/64093 Dependencies: - swiftlang/swift-docc-render#582 rdar://106153042
- Loading branch information
1 parent
2e4d3c5
commit 9634cf3
Showing
15 changed files
with
392 additions
and
15 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Sources/SwiftDocC/Model/Rendering/References/TopicColor.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,43 @@ | ||
/* | ||
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 | ||
*/ | ||
|
||
/// A color that associated with a documentation topic. | ||
public struct TopicColor: Codable, Hashable { | ||
/// A string identifier for a built-in, standard color. | ||
/// | ||
/// This value is expected to be one of the following: | ||
/// - term `blue`: A context-dependent blue color. | ||
/// | ||
/// - term `gray`: A context-dependent gray color. | ||
/// | ||
/// - term `green`: A context-dependent orange color. | ||
/// | ||
/// - term `orange`: A context-dependent orange color. | ||
/// | ||
/// - term `purple`: A context-dependent purple color. | ||
/// | ||
/// - term `red`: A context-dependent red color. | ||
/// | ||
/// - term `yellow`: A context-dependent yellow color. | ||
/// | ||
/// @Comment { | ||
/// This value is optional to allow for a future where topic colors | ||
/// can be defined by something besides the standard color identifiers. | ||
/// | ||
/// For example, we may allow fully custom colors in the future and allow | ||
/// for providing some kind of `ColorReference` here. | ||
/// } | ||
public let standardColorIdentifier: String? | ||
|
||
/// Create a topic color with the given standard color identifier. | ||
public init(standardColorIdentifier: String) { | ||
self.standardColorIdentifier = standardColorIdentifier | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
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 | ||
import Markdown | ||
|
||
/// A directive that specifies an accent color for a given documentation page. | ||
/// | ||
/// Use the `PageColor` directive to provide a hint to the renderer as to how | ||
/// the page should be accented with color. The renderer may use this color, | ||
/// depending on the context, as a foundation for other colors used on the | ||
/// page. For example, Swift-DocC-Render uses this color as the primary | ||
/// background color of a page's introduction section and adjusts other | ||
/// elements in the introduction section to account for the new background. | ||
/// | ||
/// This directive is only valid within a ``Metadata`` directive: | ||
/// | ||
/// ```markdown | ||
/// @Metadata { | ||
/// @PageColor(orange) | ||
/// } | ||
/// ``` | ||
public final class PageColor: Semantic, AutomaticDirectiveConvertible { | ||
public let originalMarkup: BlockDirective | ||
|
||
/// A context-dependent, standard color. | ||
@DirectiveArgumentWrapped(name: .unnamed) | ||
public var color: Color | ||
|
||
/// A context-dependent, standard color. | ||
public enum Color: String, CaseIterable, DirectiveArgumentValueConvertible { | ||
/// A context-dependent blue color. | ||
case blue | ||
|
||
/// A context-dependent gray color. | ||
case gray | ||
|
||
/// A context-dependent green color. | ||
case green | ||
|
||
/// A context-dependent orange color. | ||
case orange | ||
|
||
/// A context-dependent purple color. | ||
case purple | ||
|
||
/// A context-dependent red color. | ||
case red | ||
|
||
/// A context-dependent yellow color. | ||
case yellow | ||
} | ||
|
||
static var keyPaths: [String : AnyKeyPath] = [ | ||
"color": \PageColor._color, | ||
] | ||
|
||
@available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.") | ||
init(originalMarkup: BlockDirective) { | ||
self.originalMarkup = originalMarkup | ||
} | ||
} |
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
Oops, something went wrong.