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
* Remove @ from all section nav ids and links.
...to avoid overkeen link rewriting in build:contrib-docs
* Push section later on linking references. Common.
* Simplify headings: e.g. "Documenting functions"
*[Using assets in examples and descriptions](#using-assets)
15
+
*[Linking to other p5.js features](#linking)
15
16
*[Less common JSDoc tags](#less-common-jsdoc-tags)
16
17
*[Generating and previewing the reference](#generating-and-previewing-the-reference)
17
18
*[Linting the comments to find errors](#linting-the-docs)
@@ -63,7 +64,7 @@ Anything in a block in this manner will be interpreted as reference documentatio
63
64
64
65
In this style of reference comments, each comment block is further divided into individual elements, which we will have a look at next.
65
66
66
-
## Reference comment blocks for functions
67
+
## Documenting functions
67
68
68
69
In abstract, a comment block for a p5 _function_ typically looks as follows. (We've included the tags that will mark each section but the correct syntax will be shown shortly).
69
70
@@ -175,7 +176,7 @@ If you like, you can find the source code for this `sin` function in the p5 repo
175
176
176
177
Now we'll look at each section in turn.
177
178
178
-
### <aid="@description"></a>Describing the function
179
+
### <aid="description"></a>Describing the function
179
180
180
181
Example:
181
182
@@ -208,9 +209,8 @@ In some places, you may see the `@description` tag used. It explicitly marks t
208
209
209
210
#### The first sentence of the description
210
211
211
-
The first sentence in the description, in particular, should concisely summarize what the function does. It will almost always be necessary to omit detail here.
212
-
213
-
This first sentence will sometimes be presented alone with the function name (e.g. in [the function list](https://beta.p5js.org/reference/#Shape) on the front page of the reference website, where it can help the reader understand quickly if the function is what they're looking for.
212
+
The first sentence in the description, in particular, should concisely summarize what the function does.
213
+
It may be presented alone with the function name in listings (e.g. in [the function list](https://beta.p5js.org/reference/#Shape) on the front page of the reference website), where it should help the reader understand quickly if the function is what they're looking for.
214
214
215
215
**Examples of first sentences of function descriptions**
216
216
@@ -253,67 +253,6 @@ Multiplies a vector by a scalar and returns a new vector.
253
253
254
254
```
255
255
256
-
#### <a id="linking"></a>Linking to another p5.js feature
257
-
258
-
A hyperlink HTML element (with the `a` tag) can be used within a description to link to the documentation of another relevant feature of the p5.js library.
259
-
260
-
Example:
261
-
262
-
```
263
-
<a href="#/p5/circle">circle()</a>
264
-
```
265
-
266
-
Note that the URL should _not_ include a direct link to the website.
267
-
268
-
With the [exception of constants](#linking-to-constants), the URL should be of the following "fragment" or "hash" form:
269
-
270
-
`#/class/property`
271
-
272
-
Example URLs linking to functions and variables:
273
-
274
-
* `#/p5/circle`
275
-
* `#/p5/createCanvas`
276
-
* `#/p5/fill`
277
-
* `#/p5/mouseX`
278
-
* `#/p5.Vector/lerp`
279
-
* `#/p5.Vector/dist`
280
-
* `#/p5.Image/width`
281
-
282
-
Examples URLS linking to classes:
283
-
284
-
* `#/p5.Color`
285
-
* `#/p5.Image`
286
-
* `#/p5.Vector`
287
-
288
-
As seen above, when there's no property involved, just a class itself, the second slash is generally omitted.
289
-
290
-
Full examples:
291
-
292
-
From the description of [dist](https://beta.p5js.org/reference/p5/dist/) in [calculation.js](https://github.com/processing/p5.js/blob/dev-2.0/src/math/calculation.js)
293
-
```
294
-
* Use <a href="#/p5.Vector/dist">p5.Vector.dist()</a>
295
-
* to calculate the distance between two
296
-
* <a href="#/p5.Vector">p5.Vector</a> objects.
297
-
```
298
-
299
-
From the description of [pmouseX](https://beta.p5js.org/reference/p5/pmousex/):
300
-
```
301
-
* Its value is <a href="#/p5/mouseX">mouseX</a>
302
-
* from the previous frame.
303
-
```
304
-
305
-
<a id="linking-to-constants"></a>**Exception: Linking to constants**
306
-
307
-
Links to constants should instead follow this form:
308
-
309
-
`#/p5/constants/name-of-constant`
310
-
311
-
Example URLS:
312
-
313
-
* `#/p5/constants/DEGREES`
314
-
* `#/p5/constants/CENTER`
315
-
* `#/p5/constants/LEFT`
316
-
317
256
#### Using images within the description section
318
257
319
258
In some cases it may be desirable to include, in the description, images or audio or video to help explain or demonstrate a function's working.
@@ -336,15 +275,15 @@ Here's a cut-down example from the source of [`applyMatrix`](https://github.com/
336
275
* ...
337
276
```
338
277
339
-
### <a id="@method"></a>`@method` - specifying the function name
278
+
### <a id="method"></a>`@method` - specifying the function name
340
279
341
280
[`@method`](https://jsdoc.app/tags-function) is used to define the name of the function, in this case `sin`. Note that the function name does not include the brackets `()`.
342
281
343
282
You may sometimes see this missing from the reference. In that case JSDoc will try to infer it by looking at the name of the function from the following source code. It is recommended to include the function name using the @methodtag where possible.
344
283
345
284
This tag is also useful when detailing multiple signatures for a function (see later).
346
285
347
-
### <a id="@param"></a>`@param` - specifying details of each parameter
286
+
### <a id="param"></a>`@param` - specifying details of each parameter
348
287
349
288
[`@param`](https://jsdoc.app/tags-param) is used to define the parameters or arguments that the function accepts. It is used once per parameter.
350
289
@@ -451,7 +390,7 @@ Here's some of the documentation for `loadImage`, which has an optional paramete
451
390
452
391
#### Links in param descriptions
453
392
454
-
You can include links in the description of a parameter. See [linking](#linking).
393
+
You can include links in the description of a parameter. For how to link to another reference page see [linking](#linking), later.
455
394
456
395
Example:
457
396
```
@@ -460,7 +399,7 @@ Example:
460
399
* the current <a href="#/p5/angleMode">angleMode()</a>.
461
400
```
462
401
463
-
### <aid="@return"></a>`@return` - specifying the return value
402
+
### <aid="return"></a>`@return` - specifying the return value
464
403
465
404
[`@return`](https://jsdoc.app/tags-returns) is used to define the return value of the function.
466
405
@@ -482,7 +421,7 @@ If the function does not return a value, the `@return` tag can be left out.
482
421
483
422
If the function returns a value but you want it to be type `any`, use `{*}`, e.g. `@return {*} description here...`
484
423
485
-
You can include links in the description of a return. See [linking](#linking).
424
+
You can include links in the description of a return. For how to link to another reference page see [linking](#linking), later.
486
425
487
426
More examples of `@return`:
488
427
@@ -646,7 +585,7 @@ In this rare situation, it is possible to use a last-resort mechanism to inject
646
585
647
586
Bear in mind this is a last resort. Try to correctly specify the types in the documentation comments wherever possible.
648
587
649
-
## Reference comment blocks for p5.js variables
588
+
## Documenting p5.js variables
650
589
651
590
So far, we have looked at how to write references for functions. Variables follow the same structure but use different tags.
652
591
@@ -679,7 +618,7 @@ Example: the reference comment block for the built-in variable, `mouseX`:
679
618
680
619
The start of the block contains the description of the variable (`mouseX` in this case). The same rules apply from function descriptions: Use a clear short first line, you can use markdown and HTML and assets in the description.
681
620
682
-
### <aid="@property"></a>The `@property` tag
621
+
### <aid="property"></a>The `@property` tag
683
622
684
623
To define the name of the variable, we use [`@property`](https://jsdoc.app/tags-property) instead of `@method`. `@property` follows the same syntax as `@param` for defining the type and its name.
685
624
@@ -704,7 +643,7 @@ From [`src/image/p5.Image.js`](https://github.com/processing/p5.js/blob/dev-2.0/
704
643
* @property {Number[]} pixels
705
644
```
706
645
707
-
### <aid="@readonly"></a>The `@readonly` tag
646
+
### <aid="readonly"></a>The `@readonly` tag
708
647
709
648
The `@readonly` tag is present on most p5.js variables and is used internally to indicate this value should not be overwritten directly by a library user.
710
649
@@ -864,11 +803,80 @@ Finally, for every example you add, you are required to use the p5.js function `
864
803
865
804
For more on `describe()` visit the [web accessibility contributor documentation](./web_accessibility/#describe), and the [Writing Accessible Canvas Descriptions](https://beta.p5js.org/tutorials/writing-accessible-canvas-descriptions/) tutorial.
866
805
806
+
807
+
## <aid="linking"></a>Linking to other p5.js features
808
+
809
+
A hyperlink can be used within a description or `@param` or `@return` to link to the reference documentation of another relevant p5.js feature.
810
+
811
+
Example:
812
+
813
+
```
814
+
<a href="#/p5/circle">circle()</a>
815
+
```
816
+
817
+
Note that the URL should _not_ include a direct link to the website.
818
+
819
+
With the [exception of constants](#linking-to-constants), the URL should be of the following "fragment" or "hash" form:
820
+
821
+
`#/class/property`
822
+
823
+
Example URLs linking to functions and variables:
824
+
825
+
*`#/p5/circle`
826
+
*`#/p5/createCanvas`
827
+
*`#/p5/fill`
828
+
*`#/p5/mouseX`
829
+
*`#/p5.Vector/lerp`
830
+
*`#/p5.Vector/dist`
831
+
*`#/p5.Image/width`
832
+
833
+
Example URLs linking to classes:
834
+
835
+
*`#/p5.Color`
836
+
*`#/p5.Image`
837
+
*`#/p5.Vector`
838
+
839
+
As seen above, when there's no property involved, just a class itself, the second slash is generally omitted.
840
+
841
+
Full examples:
842
+
843
+
From the description of [dist](https://beta.p5js.org/reference/p5/dist/) in [calculation.js](https://github.com/processing/p5.js/blob/dev-2.0/src/math/calculation.js)
844
+
```
845
+
* Use <a href="#/p5.Vector/dist">p5.Vector.dist()</a>
846
+
* to calculate the distance between two
847
+
* <a href="#/p5.Vector">p5.Vector</a> objects.
848
+
```
849
+
850
+
From the description of [pmouseX](https://beta.p5js.org/reference/p5/pmousex/):
851
+
```
852
+
* Its value is <a href="#/p5/mouseX">mouseX</a>
853
+
* from the previous frame.
854
+
```
855
+
856
+
From the `@return` statement of [createVector()](https://beta.p5js.org/reference/p5/createVector/):
857
+
```
858
+
* @return {p5.Vector} new
859
+
* <a href="#/p5.Vector">p5.Vector</a> object.
860
+
```
861
+
862
+
863
+
<aid="linking-to-constants"></a>**Exception: Linking to constants**
864
+
865
+
Links to constants should instead follow this form:
866
+
867
+
`#/p5/constants/name-of-constant`
868
+
869
+
Example URLS:
870
+
871
+
*`#/p5/constants/DEGREES`
872
+
*`#/p5/constants/CENTER`
873
+
*`#/p5/constants/LEFT`
874
+
867
875
## Less common JSDoc tags
868
876
869
877
With all the above you should have most of the tools needed to write and edit p5.js reference comments. However, there are a few more specialized usages of JSDoc reference comments that you may come across in p5.js. These are situationally useful and not something that you need often.
870
878
871
-
### <aid="@private"></a>`@private` tag
879
+
### <aid="private"></a>`@private` tag
872
880
873
881
You can use the `@private` if a property or variable or class is private. If a feature is marked as `@private` it will not be included as part of the rendered reference on the website. This is done automatically for methods whose names start with `_`.
874
882
@@ -892,7 +900,7 @@ invert(canvas) {
892
900
893
901
### `@module` and related tags
894
902
895
-
#### <aid="@module"></a>`@module` and `@submodule`
903
+
#### <aid="module"></a>`@module` and `@submodule`
896
904
897
905
At the top of each source code file will be a comment block with a `@module` tag. A module is a top-level grouping of features in the reference pages on the website. This does _not_ necessarily correspond to any specific software `module` concept in the code itself.
898
906
@@ -929,7 +937,7 @@ For both:
929
937
*/
930
938
```
931
939
932
-
#### <aid="@for"></a>The `@for` tag
940
+
#### <aid="for"></a>The `@for` tag
933
941
934
942
The `@for` tag defines the relationship between this module and the overall `p5` class, effectively saying this module is a part of the `p5` class.
935
943
@@ -961,7 +969,7 @@ Example of `@for` and `@requires`
961
969
* @requiresconstants
962
970
*/
963
971
```
964
-
#### <aid="@beta"></a>The @beta tag - marking experimental API features
972
+
#### <aid="beta"></a>The @beta tag - marking experimental API features
965
973
966
974
This tag is used to mark that a feature is experimental and that its details may change or it may be removed. A warning will be presented explaining this on the reference page.
967
975
@@ -983,7 +991,7 @@ It should be placed on a separate line in the comment block and does not need an
983
991
*/
984
992
```
985
993
986
-
#### <aid="@deprecated"></a>The @deprecated tag
994
+
#### <aid="deprecated"></a>The @deprecated tag
987
995
988
996
Marks that a feature will be removed from a future version of p5.js, possibly also indicating a better option.
989
997
@@ -1274,25 +1282,25 @@ getRow (r) {
1274
1282
1275
1283
Click on any tag to go to its section in the text.
0 commit comments