Skip to content

Commit da20498

Browse files
Add more documentation about the @Image source value (#1167)
* Add more documentation about the @image source value Also, add some information from the images article to the @image directive documentation. * Consistently omit quotation marks and file extensions in `@Image` examples * Use a multiplication sign instead of the letter "x" in prose to refer to the 2 times scaled display mode * Apply suggestions from code review Co-authored-by: Andrea Fernandez Buitrago <[email protected]> --------- Co-authored-by: Andrea Fernandez Buitrago <[email protected]>
1 parent 531818a commit da20498

File tree

8 files changed

+51
-36
lines changed

8 files changed

+51
-36
lines changed

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Shared Directives/Chapter/Chapter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Use `Chapter` directives to organize related tutorial pages into groupings. For
2323
...
2424
2525
@Chapter(name: "SlothCreator Essentials") {
26-
@Image(source: "chapter1-slothcreatorEssentials.png", alt: "A wireframe of an app interface that has an outline of a sloth and four buttons below the sloth. The buttons display the following symbols, from left to right: snowflake, fire, wind, and lightning.")
26+
@Image(source: chapter1-slothcreatorEssentials, alt: "A wireframe of an app interface that has an outline of a sloth and four buttons below the sloth. The buttons display the following symbols, from left to right: snowflake, fire, wind, and lightning.")
2727
2828
Create custom sloths and edit their attributes and powers using SlothCreator.
2929

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Shared Directives/Image.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,48 @@ Displays an image in a tutorial.
77
}
88

99
- Parameters:
10-
- source: The name and file extension of an image in your Swift framework or package project. **(required)**
10+
- source: The name of an image in your documentation catalog ('.docc' directory). **(required)**
11+
12+
Omit the appearance (for example `~dark`) and display scale (for example `@2x`) components.
13+
The file extension component (for example `.png`) is optional and can be omitted.
14+
For more information about the components of an image filename, see <doc:adding-images>.
15+
16+
If the image name contains either whitespace characters, commas (`,`), or colons (`:`) you need to surround it with quotation marks (`"`).
1117
- alt: Alternative text that describes the image to screen readers. **(required)**
1218

1319
## Overview
1420

1521
The `Image` directive displays an image in your tutorial. Provide the name of an image and alternative text that describes the image in sufficient detail so screen readers can read that text aloud for people who are blind or have low-vision.
1622

1723
```
18-
@Image(source: "overview-hero.png", alt: "An illustration of a sleeping sloth, hanging from a tree branch.”)
24+
@Image(source: overview-hero, alt: "An illustration of a sleeping sloth, hanging from a tree branch.”)
1925
````
2026
21-
Images can exist anywhere in your code base, but it's good practice to centralize them in a resources folder. You create this folder in your documentation catalog. Within your code base, image names must be unique. Images must be in *.png*, *.jpg*, *.jpeg*, *.svg*, or *.gif* format.
27+
Images can exist anywhere in your documentation catalog ('.docc' directory). but it's good practice to use subdirectories to organize the content and assets in your documentation.
28+
Regardless of organization within your catalog, each image needs to have a unique name.
29+
30+
The supported image file extensions are `png`, `jpg`, `jpeg`, `svg` and `gif`.
2231
23-
- Tip: To differentiate tutorial images from reference documentation images, you may wish to prefix image file names with tutorial\.
32+
- Tip: To differentiate tutorial images from reference documentation images, you may wish to prefix image file names with "tutorial".
2433
2534
### Provide Image Variants
2635
27-
To ensure images render well on both standard and high-resolution displays, and in light and dark appearance modes, you can provide up to four versions of each image.
36+
To ensure that images render well on both standard and high-resolution displays, and in light and dark appearance modes,
37+
you can provide appearance and display scale-aware versions of each image by including specific components in the image filename.
38+
39+
![An image of a filename that's split into four labeled sections to highlight the individual components. From left to right, the components are the image name, the appearance mode, the display scale, and the file extension.](docc-image-filename)
40+
41+
For example, the following are all valid DocC image filenames:
2842
29-
Use the following naming conventions for your image files:
43+
- term `sloth.png`: An image that's independent of all appearance modes and display scales.
44+
- term `sloth~dark.png`: An image that's specific to dark mode, but is display-scale independent.
45+
- term `[email protected]`: An image that's specific to dark mode and the 2× display scale.
3046
31-
- term Standard Light: *[filename].[extension]*, e.g. *filename.png*
32-
- term High-Resolution Light: *[filename]@2x.[extension]*, e.g. *[email protected]*
33-
- term Standard Dark: *[filename]~dark.[extension]*, e.g. *filename~dark.png*
34-
- term High-Resolution Dark: *[filename]~dark@2x.[extension]*, e.g. *[email protected]*
47+
Omit the appearance and display scale components when specifying an image name for the `source` parameter.
48+
For example, if you write `@Image(source: overview-hero, alt: " ... ")` and the reader views that tutorial page **on a display that has dark appearance mode** enabled, the system displays *[email protected]*.
3549
36-
Exclude the resolution and appearance-variant suffixes when specifying an image name in the `source` parameter. For example, when you specify `@Image(source: "overview-hero.png", alt: " ... ")`, the appropriate variant automatically displays based on the reader's context. If the reader views the tutorial **on a display that has dark appearance mode** enabled, *[email protected]* is shown. At minimum, strive to provide high resolution variants **in light and dark appearance modes.** If you don't provide a certain variant, **the system displays the closest match.**
50+
At minimum, strive to provide high resolution variants **in light and dark appearance modes.**
51+
If you don't provide a variant that matches the readers context, the system displays the closest matching image variant.
3752
3853
### Containing Elements
3954
@@ -47,4 +62,4 @@ The following tutorial elements can include images.
4762
* ``Tutorial``
4863
* ``Volume``
4964
50-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
65+
<!-- Copyright (c) 2021-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Section/Steps/Step/Code.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ Add an ``Image`` directive to show a preview of what the reader sees after perfo
4545
Add the `sloth` parameter to initialize the `CustomizedSlothView` in the preview provider, and pass a new `Sloth` instance for the value.
4646
4747
@Code(name: "CustomizedSlothView.swift", file: "01-creating-code-02-07.swift") {
48-
@Image(source: "preview-01-creating-code-02-07.png", alt: "A portrait of a generic sloth displayed in the center of the canvas.")
48+
@Image(source: preview-01-creating-code-02-07, alt: "A portrait of a generic sloth displayed in the center of the canvas.")
4949
}
5050
}
5151
5252
@Step {
5353
Set the preview provider sloth's `name` to `"Super Sloth"`, `color` to `.blue`, and `power` to `.ice`.
5454
5555
@Code(name: "CustomizedSlothView.swift", file: "01-creating-code-02-08.swift") {
56-
@Image(source: "preview-01-creating-code-02-08.png", alt: "A portrait of an ice sloth on top, followed by four power icons below. The power icons, clockwise from top left, include: ice, fire, wind, and lightning. The ice icon is selected.")
56+
@Image(source: preview-01-creating-code-02-08, alt: "A portrait of an ice sloth on top, followed by four power icons below. The power icons, clockwise from top left, include: ice, fire, wind, and lightning. The ice icon is selected.")
5757
}
5858
5959
...
@@ -85,4 +85,4 @@ The following items can include a code element:
8585

8686
- ``Image``
8787

88-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
88+
<!-- Copyright (c) 2021-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Section/Steps/Step/Step.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Use the `Step` directive to define a single task the reader performs within a se
3030
@Step {
3131
Create the folder.
3232
33-
@Image(source: "placeholder-image.png", alt: "A screenshot using the `mkdir` command to create a folder to place SlothCreator in.")
33+
@Image(source: placeholder-image, alt: "A screenshot using the `mkdir` command to create a folder to place SlothCreator in.")
3434
}
3535
3636
...
@@ -82,4 +82,4 @@ The following items can include a step:
8282
- ``Image``
8383
- ``Video``
8484

85-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
85+
<!-- Copyright (c) 2021-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Tutorial.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ A tutorial page begins with an introduction section, defined by an ``Intro`` dir
8989
@Intro(title: "Creating and Building a Swift Package") {
9090
This tutorial guides you through creating and building a Swift Package. Use the package to add your own re-usable classes and structures.
9191
92-
@Image(source: "creating-intro.png", alt: "An image of the Swift logo.")
92+
@Image(source: creating-intro, alt: "An image of the Swift logo.")
9393
}
9494
9595
...
@@ -122,13 +122,13 @@ Define sections using the ``Section`` directive. You can optionally start with d
122122
@Step {
123123
Create the directory.
124124
125-
@Image(source: "placeholder-image.png", alt: "A screenshot showing the command to type in the terminal to create the directory.")
125+
@Image(source: placeholder-image, alt: "A screenshot showing the command to type in the terminal to create the directory.")
126126
}
127127
128128
@Step {
129129
Create the Swift Package.
130130
131-
@Image(source: "placeholder-image.png", alt: "A screenshot showing the command to type in the terminal to create the Swift package.")
131+
@Image(source: placeholder-image, alt: "A screenshot showing the command to type in the terminal to create the Swift package.")
132132
}
133133
134134
@Step {
@@ -256,4 +256,4 @@ A tutorial page can contain the following items:
256256
257257
- <doc:building-an-interactive-tutorial>
258258
259-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
259+
<!-- Copyright (c) 2021-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorials/Tutorials.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Use a text editor to add a tutorial table of contents file to your documentation
2121
Create, catalog, and care for sloths using SlothCreator.
2222
Get started with SlothCreator by building the demo app _Slothy_.
2323
24-
@Image(source: "slothcreator-intro.png", alt: "An illustration of 3 iPhones in portrait mode, displaying the UI of finding, creating, and taking care of a sloth in Slothy — the sample app that you build in this collection of tutorials.")
24+
@Image(source: slothcreator-intro, alt: "An illustration of 3 iPhones in portrait mode, displaying the UI of finding, creating, and taking care of a sloth in Slothy — the sample app that you build in this collection of tutorials.")
2525
}
2626
2727
@Chapter(name: "SlothCreator Essentials") {
28-
@Image(source: "chapter1-slothcreatorEssentials.png", alt: "A wireframe of an app interface that has an outline of a sloth and four buttons below the sloth. The buttons display the following symbols, from left to right: snowflake, fire, wind, and lightning.")
28+
@Image(source: chapter1-slothcreatorEssentials, alt: "A wireframe of an app interface that has an outline of a sloth and four buttons below the sloth. The buttons display the following symbols, from left to right: snowflake, fire, wind, and lightning.")
2929
3030
Create custom sloths and edit their attributes and powers using SlothCreator.
3131

Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/building-an-interactive-tutorial.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ Use a text editor and the following listing to create a table of contents file n
3333
@Intro(title: "Add a title for your introduction here.") {
3434
Add engaging introduction text here.
3535
36-
@Image(source: "toc-introduction-image-filename.png", alt: "Add an accessible description for your image here.")
36+
@Image(source: toc-introduction-image-filename, alt: "Add an accessible description for your image here.")
3737
}
3838
3939
@Chapter(name: "Add a chapter title here.") {
4040
Add chapter text here.
4141
42-
@Image(source: "chapter-image-filename-here.png", alt: "Add an accessible description for your image here.")
42+
@Image(source: chapter-image-filename-here, alt: "Add an accessible description for your image here.")
4343
4444
@TutorialReference(tutorial: "doc:tutorial-page-file-name-here")
4545
@TutorialReference(tutorial: "doc:another-tutorial-page-file-name-here")
@@ -65,21 +65,21 @@ Tutorial pages provide instructions that walk through using your APIs in realist
6565
@Intro(title: "Add the name of your title here.") {
6666
Add engaging introduction text here.
6767

68-
@Image(source: "intro-image-filename-here.jpg", alt: "Add an accessible description for your image here.")
68+
@Image(source: intro-image-filename-here, alt: "Add an accessible description for your image here.")
6969
}
7070

7171
@Section(title: "Add the name of your section here.") {
7272
@ContentAndMedia {
7373
Add engaging section text here.
7474

75-
@Image(source: "section-image-filename-here.jpg", alt: "Add an accessible description for your image here.")
75+
@Image(source: section-image-filename-here, alt: "Add an accessible description for your image here.")
7676
}
7777

7878
@Steps {
7979
@Step {
8080
Add engaging step 1 text here.
8181

82-
@Image(source: "step-1-image-filename-here.jpg", alt: "Add an accessible description for your step here.")
82+
@Image(source: step-1-image-filename-here, alt: "Add an accessible description for your step here.")
8383
}
8484
8585
@Step {
@@ -99,24 +99,24 @@ Replace the placeholders with your custom content. Use the ``Intro`` directive t
9999
@Intro(title: "Add a title for your tutorial page here.") {
100100
Add engaging introduction text here.
101101

102-
@Image(source: "tutorial-introduction-image-filename.png", alt: "Add an accessible description for your image here.")
102+
@Image(source: tutorial-introduction-image-filename, alt: "Add an accessible description for your image here.")
103103
}
104104

105105
@Section(title: "Add a section title here") {
106106
@ContentAndMedia {
107107
Add some content here to introduce the steps that follow.
108108

109-
@Image(source: "section-image-filename.png", alt: "Add an accessible description for your image here.")
109+
@Image(source: section-image-filename, alt: "Add an accessible description for your image here.")
110110
}
111111

112112
@Steps {
113113
@Step {
114114
Provide text for a step here.
115-
@Image(source: "step1-image-filename.png", alt: "Add an accessible description for your image here.")
115+
@Image(source: step1-image-filename, alt: "Add an accessible description for your image here.")
116116
}
117117
@Step {
118118
Provide text for another step here.
119-
@Image(source: "step2-image-filename.png", alt: "Add an accessible description for your image here.")
119+
@Image(source: step2-image-filename, alt: "Add an accessible description for your image here.")
120120
}
121121
}
122122
}
@@ -176,4 +176,4 @@ DocC compiles your documentation catalog and generates the tutorial. Copy the UR
176176
177177
Learn how to share your documentation in <doc:distributing-documentation-to-other-developers>.
178178
179-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
179+
<!-- Copyright (c) 2021-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/docc/DocCDocumentation.docc/adding-images.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For example, the following are all valid DocC image filenames:
2222

2323
- term `sloth.png`: An image that's independent of all appearance modes and display scales.
2424
- term `sloth~dark.png`: An image that's specific to dark mode, but is display-scale independent.
25-
- term `[email protected]`: An image that's specific to dark mode and the 2x display scale.
25+
- term `[email protected]`: An image that's specific to dark mode and the display scale.
2626

2727
> Important: Include the image files in your documentation catalog. For more information, see <doc:documenting-a-swift-framework-or-package>.
2828
@@ -39,4 +39,4 @@ image.
3939
![A sloth hanging off a tree.](sloth)
4040
```
4141

42-
<!-- Copyright (c) 2023 Apple Inc and the Swift Project authors. All Rights Reserved. -->
42+
<!-- Copyright (c) 2023-2025 Apple Inc and the Swift Project authors. All Rights Reserved. -->

0 commit comments

Comments
 (0)