You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Shared Directives/Chapter/Chapter.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ Use `Chapter` directives to organize related tutorial pages into groupings. For
23
23
...
24
24
25
25
@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.")
27
27
28
28
Create custom sloths and edit their attributes and powers using SlothCreator.
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Shared Directives/Image.md
+27-12Lines changed: 27 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,33 +7,48 @@ Displays an image in a tutorial.
7
7
}
8
8
9
9
- 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 (`"`).
11
17
- alt: Alternative text that describes the image to screen readers. **(required)**
12
18
13
19
## Overview
14
20
15
21
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.
16
22
17
23
```
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.”)
19
25
````
20
26
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`.
22
31
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".
24
33
25
34
### Provide Image Variants
26
35
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
+

40
+
41
+
For example, the following are all valid DocC image filenames:
28
42
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.
30
46
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]*.
35
49
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.
37
52
38
53
### Containing Elements
39
54
@@ -47,4 +62,4 @@ The following tutorial elements can include images.
47
62
* ``Tutorial``
48
63
* ``Volume``
49
64
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. -->
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Section/Steps/Step/Code.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,15 +45,15 @@ Add an ``Image`` directive to show a preview of what the reader sees after perfo
45
45
Add the `sloth` parameter to initialize the `CustomizedSlothView` in the preview provider, and pass a new `Sloth` instance for the value.
@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.")
57
57
}
58
58
59
59
...
@@ -85,4 +85,4 @@ The following items can include a code element:
85
85
86
86
-``Image``
87
87
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. -->
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Section/Steps/Step/Step.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Use the `Step` directive to define a single task the reader performs within a se
30
30
@Step {
31
31
Create the folder.
32
32
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.")
34
34
}
35
35
36
36
...
@@ -82,4 +82,4 @@ The following items can include a step:
82
82
-``Image``
83
83
-``Video``
84
84
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. -->
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorial/Tutorial.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ A tutorial page begins with an introduction section, defined by an ``Intro`` dir
89
89
@Intro(title: "Creating and Building a Swift Package") {
90
90
This tutorial guides you through creating and building a Swift Package. Use the package to add your own re-usable classes and structures.
91
91
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.")
93
93
}
94
94
95
95
...
@@ -122,13 +122,13 @@ Define sections using the ``Section`` directive. You can optionally start with d
122
122
@Step {
123
123
Create the directory.
124
124
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.")
126
126
}
127
127
128
128
@Step {
129
129
Create the Swift Package.
130
130
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.")
132
132
}
133
133
134
134
@Step {
@@ -256,4 +256,4 @@ A tutorial page can contain the following items:
256
256
257
257
- <doc:building-an-interactive-tutorial>
258
258
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. -->
Copy file name to clipboardExpand all lines: Sources/docc/DocCDocumentation.docc/Reference Syntax/Tutorials Syntax/Top-Level Directives/Tutorials/Tutorials.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ Use a text editor to add a tutorial table of contents file to your documentation
21
21
Create, catalog, and care for sloths using SlothCreator.
22
22
Get started with SlothCreator by building the demo app _Slothy_.
23
23
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.")
25
25
}
26
26
27
27
@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.")
29
29
30
30
Create custom sloths and edit their attributes and powers using SlothCreator.
0 commit comments