Skip to content

Commit 8c10339

Browse files
authored
Move doc directive documentation to source code (#3521)
1 parent 4283dbc commit 8c10339

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.settings/
99
.vscode/
1010
build/
11-
doc/
11+
doc/api/
1212
lcov.info
1313
test_data/
1414
testing/**/doc

doc/directives.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Dartdoc supports several **directives** within Dart doc comments. Each directive
2+
is then processed during documentation generation, and new text is inserted in
3+
place of the directive. Not all directives are supported for package
4+
documentation at https://pub.dev/.
5+
6+
A doc comment directive consists of either one directive tag, which looks
7+
something like `{@DIRECTIVE ARG=VALUE ...}`, or two such tags (an opening and a
8+
closing tag), with content in between.
9+
10+
The supported directives are listed below:
11+
12+
## `@nodoc` - Do not include documentation
13+
14+
An element whose doc comment should not appear in the generated documenation can
15+
include the `@nodoc` directive.
16+
17+
Note that the `@nodoc` directive does not have curly braces, like most of the
18+
other directives.
19+
20+
## `{@category}` and `{@subCategory}` - Categories
21+
22+
Elements such as libraries and classes can be grouped into categories and
23+
sub-categories by adding `{@category CATEGORY NAME}` and
24+
`{@subCategory SUB-CATEGORY NAME}` in doc comments. Each category then gets its
25+
own documentation page, listing all of the categorized elements.
26+
27+
## `{@template}` and `{@macro}` - Templates and macros
28+
29+
TODO(srawlins): Document.
30+
31+
## `{@example}` - Examples (deprecated)
32+
33+
Examples from the file system can be inlined by using the `{@example}`
34+
directive. The file path, the region, and the example language can all be
35+
specified with the following syntax:
36+
37+
```none
38+
/// {@example PATH [region=NAME] [lang=NAME]}
39+
```
40+
41+
All example file names must have the extension, `.md`, and this extension must
42+
not be specified in the example `PATH`. `PATH` must be specified as a relative
43+
path from the root of the project for which documentation is being generated.
44+
Given `dir/file.dart` as `PATH`, an example will be extracted from
45+
`dir/file.dart.md`, relative to the project root directory.
46+
47+
During doc generation, dartdoc will replace the `{@example}` directive with the
48+
contents of the example file, verbatim.
49+
50+
TODO(srawlins): Document region, lang, `--example-path-prefix`.
51+
52+
## `{@inject-html}` - Injected HTML
53+
54+
HTML can be rendered unmodified by including it between `{@inject-html}` and
55+
`{@end-inject-html}` directive tags. The tags take no arguments:
56+
57+
```none
58+
/// {@inject-html}
59+
/// <p>Injected HTML.</p>
60+
/// {@end-inject-html}
61+
```
62+
63+
The `{@inject-html}` directive is only available when the `--inject-html` flag
64+
is passed to `dart doc`. It is not available for documentation published on
65+
https://pub.dev.
66+
67+
## `{@animation}` - Animations
68+
69+
HTML5 videos can be embedded with the `{@animation}` directive. This directive
70+
accepts width and height arguments, and an optional ID argument:
71+
72+
```none
73+
/// {@animation 320 240 URL [id=ID]}
74+
```
75+
76+
This directive renders the HTML which embeds an HTML5 video.
77+
78+
The optional ID should be a unique id that is a valid JavaScript identifier, and
79+
will be used as the id for the video tag. If no ID is supplied, then a unique
80+
identifier (starting with "animation_") will be generated.
81+
82+
The width and height must be integers specifying the dimensions of the video
83+
file in pixels.
84+
85+
## `{@youtube}` - YouTube videos
86+
87+
A YouTube video can be embedded with the `{@youtube}` directive. This directive
88+
accepts width and height arguments, using the following syntax:
89+
90+
```none
91+
/// {@youtube 320 240 https://www.youtube.com/watch?v=oHg5SJYRHA0}
92+
```
93+
94+
This directive embeds the YouTube video with id "oHg5SJYRHA0" into the
95+
documentation page, with a width of 320 pixels, and a height of 240 pixels. The
96+
height and width are used to calculate the aspect ratio of the video; the video
97+
is always rendered to take up all available horizontal space to accommodate
98+
different screen sizes on desktop and mobile.
99+
100+
The video URL must have the following format:
101+
`https://www.youtube.com/watch?v=oHg5SJYRHA0`. This format can usually be found
102+
in the address bar of the browser when viewing a YouTube video.
103+
104+
## `{@tool}` - External tools
105+
106+
TODO(srawlins): Document.
107+
108+
## `{@canonicalFor}` - Canonicalization
109+
110+
Dartdoc uses some heuristics to decide what the public-facing libraries are,
111+
and which public-facing library is the "canonical" location for an element.
112+
When that heuristic needs to be overridden, a user can use this directive.
113+
Example:
114+
115+
```none
116+
/// {@canonicalFor some_library.SomeClass}
117+
```
118+
119+
When this directive is used on a library's doc comment, that library is marked
120+
as the canonical library for `some_library.SomeClass`.

0 commit comments

Comments
 (0)