Skip to content

Commit fee9031

Browse files
authored
Update content formatting documentation with symbol link enhancements (#588)
* Update content formatting documentation with symbol link enhancements * Minor phrasing adjustments about link disambiguation
1 parent ed44423 commit fee9031

File tree

1 file changed

+117
-47
lines changed

1 file changed

+117
-47
lines changed

Sources/docc/DocCDocumentation.docc/formatting-your-documentation-content.md

+117-47
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@ space. For the page title of an article or API collection, use plain text only.
2525
> Important: Page titles must be the first line of content in a documentation
2626
file. One or more empty lines can precede the page title.
2727

28-
For the page title of a framework landing page or extension file, use a _symbol
29-
link_. To create a symbol link, wrap the framework's name, or the symbol's name
30-
(including its hierarchy within the framework, when necessary), within a set of
31-
double backticks (\`\`).
28+
For the page title of a landing page, enter a symbol link by wrapping the framework's
29+
module name within a set of double backticks (\`\`).
3230

3331
```markdown
3432
# ``SlothCreator``
33+
```
34+
35+
For a documentation extension file, enter a symbol link by wrapping the path to the symbol
36+
within double backticks (\`\`). The path may start with the framework's module name
37+
or with the name of a top-level symbol in the module.
38+
39+
The following example shows a documentation extension link starting with a framework module name:
40+
41+
```markdown
3542
# ``SlothCreator/CareSchedule/Event``
3643
```
3744

45+
The following example shows a documentation extension link to the same symbol starting with a top-level symbol name:
46+
47+
```markdown
48+
# ``CareSchedule/Event``
49+
```
50+
3851
Augment every page title with a short and concise single-sentence abstract or
3952
summary that provides additional information about the content. Add the summary
4053
using a new paragraph directly below the page title.
@@ -69,7 +82,7 @@ DocC provides three ways to format the text in your documentation. You can
6982
apply bold or italic styling, or you can use code voice, which renders the
7083
specified text in a monospace font.
7184

72-
To add bold styling, wrap the text in a pair of double asterisks (`**`) or you can wrap it in a pair of double underscores (`__`) .
85+
To add bold styling, wrap the text in a pair of double asterisks (`**`).
7386
Alternatively, use double underscores (`__`).
7487

7588
The following example uses bold styling for the names of the sloths:
@@ -157,9 +170,9 @@ struct Sightseeing: Activity {
157170
}
158171
```
159172

160-
The following table lists the names of programming languages that can be used
161-
to specify the syntax highlighting for a given code listing. Each one may have
162-
aliases that can also be used to specify the same language.
173+
The following table lists the names of the programming languages you can specify
174+
to enable syntax highlighting for a particular code listing. Each language may
175+
have one or more aliases.
163176

164177
| Name | Aliases |
165178
| ---------- | ------------------------------------------------------ |
@@ -202,7 +215,7 @@ To add a link to a symbol, wrap the symbol's name in a set of double backticks
202215
``SlothCreator``
203216
```
204217

205-
For nested symbols, include the entire path to the symbol in the link.
218+
For nested symbols, include the path to the symbol in the link.
206219

207220
```markdown
208221
``SlothCreator/Sloth/eat(_:quantity:)``
@@ -213,7 +226,7 @@ a symbol link that appears inline in the `Sloth` class, and targets a
213226
symbol in that class, can omit the `SlothCreator/Sloth/` portion of the symbol
214227
path.
215228

216-
In some cases, a symbol's path isnt unique, such as with overloaded methods in
229+
In some cases, a symbol's path isn't unique, such as with overloaded methods in
217230
Swift. For example, consider the `Sloth` structure, which has multiple
218231
`update(_:)` methods.
219232

@@ -235,56 +248,113 @@ mutating public func update(_ energyLevel: Int) {
235248

236249
Both methods have an identical symbol path of `SlothCreator/Sloth/update(_:)`.
237250
In this scenario, and to ensure uniqueness, DocC uses the symbol's unique
238-
identifier instead of its name to disambiguate.
251+
identifier instead of its name to disambiguate. DocC's warnings about ambiguous
252+
symbol links suggests one disambiguation for each of the symbols that match the
253+
ambiguous symbol path.
239254

240255
```markdown
241256
### Updating Sloths
242257
- ``Sloth/update(_:)-4ko57``
243258
- ``Sloth/update(_:)-jixx``
244259
```
245260

246-
In the example above, both symbol paths are identical, regardless of text case.
247-
However, another scenario where you need to provide more context to DocC about
248-
the symbol you're linking is when the case-insensitive nature of symbol paths
249-
comes into play. For example, consider the `Sloth` structure, which has a nested
250-
`Color` enumeration and a `color` property.
261+
In the example above, both symbols are functions so you need the unique
262+
identifiers to disambiguate the `Sloth/update(_:)` link.
263+
264+
Unique identifiers aren't the only way to disambiguate symbol links. If a symbol
265+
has a different type from the other symbols with the same symbol path, you can
266+
use that symbol's type suffix to disambiguate the link and make the link refer
267+
to that symbol. For example, consider a `Color` structure with `red`, `green`,
268+
and `blue` properties for color components and static properties for a handful
269+
of predefined color values.
251270

252271
```swift
253-
public struct Sloth {
254-
public enum Color { }
255-
256-
public var color: Color
272+
public struct Color {
273+
public var red, green, blue: Double
274+
}
275+
276+
extension Color {
277+
public static let red = Color(red: 1.0, green: 0.0, blue: 0.0)
278+
public static let purple = Color(red: 0.5, green: 0.0, blue: 0.5)
279+
public static let blue = Color(red: 0.0, green: 0.0, blue: 1.0)
257280
}
258281
```
259282

260-
Because symbol paths are case-insensitive, both symbols resolve to the same path.
261-
To address this issue, add the suffix for the target's type to the linked symbol path .
283+
Both the `red` property and the `red` static property have a symbol path of
284+
`Color/red`. Because these are different types of symbols you can disambiguate
285+
`Color/red` with symbol type suffixes instead of the symbols' unique identifiers.
286+
287+
The following example shows a symbol link to the `red` property:
288+
289+
```markdown
290+
``Color/red-property``
291+
```
292+
293+
The following example shows a symbol link to the `red` static property:
262294

263295
```markdown
264-
``Sloth/Color.swift-enum``
296+
``Color/red-type.property``
265297
```
266298

267299
DocC supports the following symbol types for use in symbol links:
268300

269-
| Symbol type | Suffix |
270-
| ----------- | ------ |
271-
| Enumeration | `-swift.enum` |
272-
| Enumeration case | `-swift.enum.case` |
273-
| Protocol | `-swift.protocol` |
274-
| Operator | `-swift.func.op` |
275-
| Typealias | `-swift.typealias` |
276-
| Function | `-swift.func` |
277-
| Structure | `-swift.struct` |
278-
| Class | `-swift.class` |
279-
| Type property | `-swift.type.property` |
280-
| Type method | `-swift.type.method` |
281-
| Type subscript | `-swift.type.subscript` |
282-
| Property | `-swift.property` |
283-
| Initializer | `-swift.init` |
284-
| Deinitializer | `-swift.deinit` |
285-
| Method | `-swift.method` |
286-
| Subscript | `-swift.subscript` |
301+
| Symbol type | Suffix |
302+
|-------------------|-------------------|
303+
| Enumeration | `-enum` |
304+
| Enumeration case | `-enum.case` |
305+
| Protocol | `-protocol` |
306+
| Operator | `-func.op` |
307+
| Typealias | `-typealias` |
308+
| Function | `-func` |
309+
| Structure | `-struct` |
310+
| Class | `-class` |
311+
| Type property | `-type.property` |
312+
| Type method | `-type.method` |
313+
| Type subscript | `-type.subscript` |
314+
| Property | `-property` |
315+
| Initializer | `-init` |
316+
| Deinitializer | `-deinit` |
317+
| Method | `-method` |
318+
| Subscript | `-subscript` |
319+
| Instance variable | `-ivar` |
320+
| Macro | `-macro` |
321+
| Module | `-module` |
322+
323+
Symbol type suffixes can include a source language identifier prefix — for
324+
example, `-swift.enum` instead of `-enum`. However, the language
325+
identifier doesn't disambiguate the link.
326+
327+
Symbol paths are case-sensitive meaning that symbols with the same name in
328+
different text casing don't need disambiguation.
329+
330+
Symbols that have representations in both Swift and Objective-C can use
331+
symbol paths in either source language. For example, consider a `Sloth`
332+
class with `@objc` attributes.
333+
334+
```swift
335+
@objc public class Sloth: NSObject {
336+
@objc public init(name: String, color: Color, power: Power) {
337+
self.name = name
338+
self.color = color
339+
self.power = power
340+
}
341+
}
342+
```
343+
344+
A symbol link to the Sloth initializer can be written using the symbol
345+
path in either source language.
287346

347+
**Swift name**
348+
349+
```markdown
350+
``Sloth/init(name:color:power:)``
351+
```
352+
353+
**Objective-C name**
354+
355+
```markdown
356+
``Sloth/initWithName:color:power:``
357+
```
288358

289359
To add a link to an article, use the less-than symbol (`<`), the `doc` keyword,
290360
a colon (`:`), the name of the article, and a greater-than symbol
@@ -319,20 +389,20 @@ add the link's URL destination within the parentheses.
319389
DocC extends Markdown's image support so you can provide appearance and
320390
display scale-aware versions of an image. You use specific components to create image filenames, and DocC uses the most appropriate version of the image when displaying your documentation.
321391

322-
![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 apperance mode, the display scale, and the file extension.](docc-image-filename)
392+
![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)
323393

324394
| Component | Description |
325395
| --- | --- |
326396
| Image name | **Required**. Identifies the image within the documentation catalog. The name must be unique across all images in the catalog, even if you store them in separate folders. |
327-
| Appearance | **Optional**. Identifies the appearance mode in which DocC uses the image. Add `~dark` directly after the image name to identify the image as a dark appearance mode variant. |
397+
| Appearance | **Optional**. Identifies the appearance mode in which DocC uses the image. Add `~dark` directly after the image name to identify the image as a dark mode variant. |
328398
| Display scale | **Optional**. Identifies the display scale at which DocC uses the image. Possible values are `@1x`, `@2x`, and `@3x`. When specifying a display scale, add it directly before the file extension. |
329399
| File extension | **Required**. Identifies the type of image, such as .png or .jpeg. |
330400

331401
For example, the following are all valid DocC image filenames:
332402

333403
- term `sloth.png`: An image that's independent of all appearance modes and display scales.
334-
- term `sloth~dark.png`: An image that's specific to a dark appearance mode, but is display-scale independent.
335-
- term `[email protected]`: An image that's specific to a dark appearance mode and the 2x display scale.
404+
- term `sloth~dark.png`: An image that's specific to dark mode, but is display-scale independent.
405+
- term `[email protected]`: An image that's specific to dark mode and the 2x display scale.
336406

337407
> Important: You must store images you include in your documentation in a
338408
documentation catalog. For more information, see <doc:documenting-a-swift-framework-or-package>.
@@ -349,7 +419,7 @@ display scale, and file extension components. Don't include the path to the
349419
image, even if you store the image in a folder in the documentation catalog.
350420

351421
```markdown
352-
![A photograph of a sloth hanging off a tree.](sloth)
422+
![A sloth hanging off a tree.](sloth)
353423
```
354424

355425
### Add Bulleted, Numbered, and Term Lists
@@ -499,4 +569,4 @@ DocC doesn't prematurely terminate the styling.
499569
**Sloths require sustenance\*\* to perform activities.**
500570
```
501571

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

0 commit comments

Comments
 (0)