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
misc on inline ref guide, style guide, how ref gen works, add two json examples (folder)
add note about PR 1121 - "broken p5.* links"
question on jsdoc best practices doc
started a section on how reference-generation works
this likely should go in a separate document
add example json from reference generation (+new folder)
doc style guide: update and link to inline reference guide
correct the final "Assets" section
clarify that @module and @submodule are for documentation purposes
mention @submodule and @for missing from jsdoc
@@ -10,9 +10,9 @@ In p5.js, we author the code reference you see on the [reference](https://p5js.o
10
10
11
11
This document will show you how to write and format the reference comments so that they can eventually be rendered onto the website correctly. You should follow this guide whenever you are editing or writing a reference for any p5.js function or variable.
12
12
13
-
### Aside: A note about versions
13
+
### A note about versions
14
14
15
-
This document primarily describes p5 version 2.x, whose reference documentation is currently being hosted at https://beta.p5js.org/reference/. Important differences between how p5 v1.x and v2.x are documented will be mentioned in order to help the reader who encounters examples of both formats - or tooling - in the wild.
15
+
This document describes p5.js version 2.x, whose reference documentation is currently being hosted at https://beta.p5js.org/reference/. Important differences between how p5 v1.x and v2.x are documented will be mentioned in order to help the reader who encounters examples of both formats - or tooling - in the wild.
16
16
17
17
## A quick introduction to how reference comments work
18
18
@@ -112,7 +112,7 @@ Note that block comments starting with `/*` rather than `/**` will be _ignored_
112
112
113
113
### Differences between p5 v1 and v2
114
114
115
-
Note that p5 v1.x does _not_ use JSDoc syntax but a slightly modified [syntax called YUIDoc](https://yui.github.io/yuidoc/syntax/index.html). In practice the syntaxes are largely compatible but there _are_differences.
115
+
Note that p5 v1.x does _not_ use JSDoc syntax but a slightly modified [syntax called YUIDoc](https://yui.github.io/yuidoc/syntax/index.html). In practice the syntaxes are largely compatible but there are some differences. This document will highlight any important ones. See also the list in [this appendix](#appendix-syntax-differences-between-yuidoc-and-jsdoc").
116
116
117
117
Syntax and tooling per version
118
118
@@ -692,12 +692,39 @@ p5.prototype._start = function () {
692
692
693
693
### `@module` and related tags
694
694
695
-
At the top of each source code file will be a `@module` tag. Modules correspond to a group of features in p5.js which on the rendered reference page on the website are split into the corresponding sections. Inside each module, there are additional submodules defined with the `@submodule` tag.
695
+
#### @module and @submodule
696
+
697
+
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 iteself.
698
+
699
+
After the `@module` tag, an optional `@submodule` tag can be used to further group features for the website. This `@submodule` tag can be set differently on any comment block in the file to change the submodule for a specific feature.
700
+
701
+
The convention p5.js follows is that each subfolder in the `src/` folder will be one `@module` while each file inside the subfolder will be its own `@submodule` under the overall subfolder’s `@module`. Unless you are adding new subfolders/files to the p5.js source code, you shouldn’t need to edit a file's top-level reference comment block.
702
+
703
+
On the website, the [top-level reference page](https://beta.p5js.org/reference) presents a list functions and variables grouped by their modules and submodules.
704
+
705
+
Examples:
706
+
707
+
The ["Image" module](https://beta.p5js.org/reference/#Image) in `src/image` has the following submodules: "Loading & Displaying", "Pixels", and "p5.Image".
708
+
709
+
The ["Color" module](https://beta.p5js.org/reference/#Color) in `src/color` has the following submodules:
710
+
"Creating & Reading", "Setting", and "Color Conversion".
711
+
712
+
The _conceptual_ ["3D" module](https://beta.p5js.org/reference/#3D) documents code mostly from `src/webgl` (there is no `src/3D`), and has the following submodules: "Camera", "Interaction", "Lights", "Material", "strands", "p5.Camera", "p5.Shader".
713
+
714
+
#### The @for tag
696
715
697
716
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.
698
717
718
+
<!-- TODO: clarify the nature of this relationship documented by the @for tag. Where might this be used - still only in docs? also in type-gen? elsewhere? -->
719
+
720
+
#### The @requires tag
721
+
699
722
The `@requires` tag defines the required imported modules that the current module depends on.
700
723
724
+
<!-- TODO: clarify where this @requires info is made use of. What responsibilities does the author have to state these correctly and comprehensively? -->
725
+
726
+
Example of `@for` and `@requires`
727
+
701
728
```js
702
729
/**
703
730
* @moduleColor
@@ -708,8 +735,6 @@ The `@requires` tag defines the required imported modules that the current modul
708
735
*/
709
736
```
710
737
711
-
The convention p5.js follows is that each subfolder in the `src/` folder will be one `@module` while each file inside the subfolder will be its own `@submodule` under the overall subfolder’s `@module`. Unless you are adding new subfolders/files to the p5.js source code, you shouldn’t need to edit this reference comments block.
712
-
713
738
714
739
### `@class` tag
715
740
@@ -813,6 +838,10 @@ npm run custom:cleanup
813
838
814
839
* YUIDoc requires function names be provided with the `@method` tag, whereas JSDoc can generally extract that information from the implementation source code.
815
840
841
+
* JSDoc does not have either `@submodule` or `@for` tags (YUIDoc does) but we continue to use them throughout the v2.x codebase as a mechanism by which we group functions, variables, and classes on the website. If you run `documentation lint` you'llseecomplaintsaboutthesetagbutDocumentation.jscollectsthetaggedinformationintoitsoutputwithoutproblem.
842
+
843
+
*YUIDoccodeexamples (tagged with @example) areautomaticallywrappedwith`<span>`andothermarkup. Fordocumentation.js, wewritethewrapping`<div>`and`<code>`elementsaroundtheexamplecodeourselves.
@@ -827,15 +856,16 @@ For the syntactic differences between YUIDoc and JSDoc, see above. Here are som
827
856
828
857
## Appendix: About the reference-generation process
829
858
830
-
In the p5.js repo, `npm run docs` runs (roughly):
831
-
```bash
832
-
"documentation build ./src/**/*.js
833
-
-o ./docs/data.json
834
-
&& node ./utils/convert.mjs",
835
-
```
836
-
### Flow diagram for reference generation
859
+
<!-- TODO: move this out to a separate linked file -->
860
+
861
+
You don'tneedtoknow_any_ofthefollowingtosuccessfullywriteandmaintainthereferencecommentsinthep5.jslibrary!
862
+
863
+
Here's how things work in Feb 2026 - be wary, this description may well be out of date!
864
+
865
+
//TODO: attach a label/caption. The following prose is essentially the correct screenreader text.
866
+
867
+
#### Flow diagram for reference generation
837
868
838
-
See [mermaid flowchart syntax reference](https://mermaid.ai/open-source/syntax/flowchart.html)
839
869
840
870
```mermaid
841
871
graph LR
@@ -857,10 +887,115 @@ graph LR
857
887
end
858
888
859
889
```
860
-
### Flow diagram for search index generation
890
+
891
+
#### reference generation explained
892
+
893
+
Either a human or Google Actions (CI) executes this command from the p5.js repo:
894
+
```bash
895
+
npm run docs
896
+
```
897
+
You can run it locally and observe the outputs.
898
+
899
+
* TODO: what should be true once this command finishes?
900
+
* TODO: when does this command get run?
901
+
902
+
In turn this command runs:
903
+
904
+
```bash
905
+
"documentation build ./src/**/*.js
906
+
-o ./docs/data.json
907
+
&& node ./utils/convert.mjs",
908
+
```
909
+
910
+
This is actually two commands, first `documentation build ...`, and then - if the first command was successful `node ./utils/convert.mjs`. We'lllookattheseinturn.
`documentation build`isthe [standardway](https://github.com/documentationjs/documentation?tab=readme-ov-file) to invoke documentation.js to build docs.
919
+
920
+
* The `-o` is used to specify the output file.
921
+
*`documentation.js`'s default output format is JSON, so JSON content is written into the output file.
922
+
923
+
It's important to note this output does not generate HTML pages, even though that's a common use for tools like documentation.js.
924
+
925
+
You can run this command yourself locally and inspect the output file to see the gathered data.
926
+
927
+
You can also run `npx documentation build --help` to read the manual page for documentation.js.
928
+
929
+
#### The `node ./utils/convert.mjs` command
930
+
931
+
The second command is
932
+
```bash
933
+
node ./utils/convert.mjs
934
+
```
935
+
936
+
This will _only_ run if the documentation build command runs successfully.
937
+
938
+
The `./utils/convert.mjs` script reads the output file generated by the `documentation build` command (the JSON file `/docs/data.json`), and creates three new output files:
939
+
* `/docs/reference/data.json` - Used by the p5.js-website to generate the reference pages
940
+
* `/docs/reference/data.min.json` - A smaller version of the above
941
+
* `/docs/parameterData.json`
942
+
943
+
The file generated initially by `documentation build` is _very_ large with a lot of data our pages won't need. Further, pieces of information are also scattered over the file - we'd like to group them together into a structure that will make it easier to use in later webpage generation.
944
+
The convert script has taken only what's necessary and grouped it together into the newdata file `/docs/reference/data.json` and its minified version.
945
+
946
+
This file will be used by the p5.js-website to generate the final pages, and by another build process on p5.js repo to build the types.
947
+
948
+
TODO: link to type-generation process description elsewhere.
949
+
950
+
It has also generated /docs/parameterData.json` which is used by the friendly error system (FES) at runtime to validate function parameters.
951
+
952
+
#### Excerpt of /docs/reference.data.json
953
+
954
+
Here's an excerpt from `/docs/reference/data.json`, showing how our `sin` function documentation is now represented at the end of `npm run docs`
955
+
956
+
```json
957
+
{
958
+
"name":"sin",
959
+
"file":"src/math/trigonometry.js",
960
+
"line":526,
961
+
"itemtype":"method",
962
+
"description":"<p>Calculates the sine of an angle.</p>\n<p><code>sin()</code> is useful for many geometric tasks in creative coding. The values\nreturned oscillate between -1 and 1 as the input angle increases. <code>sin()</code>\ncalculates the sine of an angle, using radians by default, or according to\nif <a href=\"#/p5/angleMode\">angleMode()</a> setting (RADIANS or DEGREES).</p>\n",
963
+
"example": [
964
+
"<div>\n<code>\nfunction setup() {\n createCanvas(100, 100);\n\n describe('A white ball on a string oscillates up and down.');\n}\n\nfunction draw() {\n background(200);\n\n // Calculate the coordinates.\n let x = 50;\n let y = 30 * sin(frameCount * 0.05) + 50;\n\n // Draw the oscillator.\n line(50, y, x, y);\n circle(x, y, 20);\n}\n</code>\n</div>\n\n<div>\n<code>\nfunction setup() {\n createCanvas(100, 100);\n\n background(200);\n\n describe('A series of black dots form a wave pattern.');\n}\n\nfunction draw() {\n // Calculate the coordinates.\n let x = frameCount;\n let y = 30 * sin(x * 0.1) + 50;\n\n // Draw the point.\n point(x, y);\n}\n</code>\n</div>\n\n<div>\n<code>\nfunction setup() {\n createCanvas(100, 100);\n\n background(200);\n\n describe('A series of black dots form an infinity symbol.');\n}\n\nfunction draw() {\n // Calculate the coordinates.\n let x = 30 * cos(frameCount * 0.1) + 50;\n let y = 10 * sin(frameCount * 0.2) + 50;\n\n // Draw the point.\n point(x, y);\n}\n</code>\n</div>"
965
+
],
966
+
"overloads": [
967
+
{
968
+
"params": [
969
+
{
970
+
"name":"angle",
971
+
"description":"the angle, in radians by default, or according to if <a href=\"/reference/p5/angleMode/\">angleMode()</a> setting (RADIANS or DEGREES).",
972
+
"type":"Number"
973
+
}
974
+
],
975
+
"return": {
976
+
"description":"sine of the angle.",
977
+
"type":"Number"
978
+
}
979
+
}
980
+
],
981
+
"return": {
982
+
"description":"sine of the angle.",
983
+
"type":"Number"
984
+
},
985
+
"class":"p5",
986
+
"static":false,
987
+
"module":"Math",
988
+
"submodule":"Trigonometry"
989
+
},
990
+
```
991
+
992
+
## Appendix: Flow diagram for search index generation
861
993
862
994
On the p5js-website repo, we run `npm run build:search`
863
995
996
+
997
+
See [mermaid flowchart syntax reference](https://mermaid.ai/open-source/syntax/flowchart.html)
* where should assets instructions live (where to put store assets and how to refer to them)? in the [documentation style guide](./documentation_style_guide.md) or here?
888
1025
* Finish and place the flow diagrams for doc-gen. ?where?
889
1026
* Replace first example in Adding examples - it doesn't run no setup or draw. allowed but v unusual in the repo.
890
1027
* perhaps acknowledge that there are limits to the types info we can carry in JSDoc and that types are currently sometimes patched in patch.mjs.
@@ -895,19 +1032,35 @@ On the p5js repo...
895
1032
* check if tagging incomplete snippets in the markdown as js is harmless (e.g. doesn't break the highlighter library). It provides useful best-effort syntax-highlighting in some contexts, helping to spot errors.
896
1033
* ? run a comprehensive broken-link check? broken example check? develop one?
897
1034
* add a ToC? there's one on the side panel but it doesn't give a good overview.
1035
+
* document the @beta tag (used in e.g. p5.strands)
898
1036
899
1037
## TODO: Questions to ask
1038
+
* Opinions on keeping [JSDoc best practices](https://beta.p5js.org/contribute/jsdoc/) separate? merging it?
1039
+
1040
+
* Check what this is doing at the top of image.js:
1041
+
```
1042
+
* @module Image
1043
+
* @submodule Image
1044
+
```
1045
+
* is it attempting to create a submodule to be presented as a sibling of the other submodules?
1046
+
* saying the features should be categorised without a distinct submodule? (for that, it's possible to omit the submodule tag)
1047
+
1048
+
900
1049
* What's the url-forming rule for in-documentation linking?
901
1050
```
902
1051
`#/p5/circle` goes to `p5/circle` but
903
1052
`#/p5.Vector` goes to `p5/p5.Vector`
904
1053
??? goes to `p5.Vector/setMag`
905
1054
??? goes to `p5.Vector/fromAngle`
906
1055
1056
+
Also see ["#1121 Fix broken p5.* reference links in reference pages"](https://github.com/processing/p5.js-website/pull/1121).
1057
+
907
1058
```
908
1059
* The existing guide shows how to write examples with no setup or draw fn, which are auto-wrapped in setup. Codebase doesn't use this. Downplay / remove the mention of this mechanism?
909
1060
* Accept this? "Generally, each example should be a self-contained complete sketch that will run on the reference website and which could be run directly if pasted into the web editor (for example)."
910
-
* Accept the following?: Multiple examples are not always separated by @example in the repo. JSDoc says they should be, so i've said that. The guide previously said just put a blank line and then new codeblock.
1061
+
* Accept the following?: Multiple examples are not always separated by @example in the repo. JSDoc says they should be, so i've said that. The guide previously said just put a blank line and then new codeblock. Examples where used: ellipse in src/shape/2d_primitives.js
1062
+
* regex to find interleave @example tag use `+\**<\/div>\n *\**\n *\**@example`
1063
+
911
1064
* assets:
912
1065
* ? say anything about licensing (e.g. for assets)
913
1066
* ? say anything about preferred file formats (for size, for browser compat, for licensing?)
@@ -923,3 +1076,8 @@ On the p5js repo...
923
1076
924
1077
## Resolved questions
925
1078
* Whether to recommend omitting @method tag or not? I'm assuming no: its presence reduces ambiguity and helps codebase search.
1079
+
* Confirm that @module and @submodule are constructs for documentation organisation, and don't necessarily indicate the existence of actual software modules of the same name. (I'm happy that's so)
1080
+
1081
+
### Author appendix: useful tools
1082
+
1083
+
* grep for modules that don't have submodules: `@module \w+\n +\*+@[^s]`
Copy file name to clipboardExpand all lines: contributor_docs/documentation_style_guide.md
+18-13Lines changed: 18 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Our community is large and diverse. Many people learn to code using p5.js, and a
15
15
## Table of Contents
16
16
17
17
### Writing
18
-
-[documentation.js and JSDoc](#documentation.js-and-jsdoc)
18
+
-[documentation.js and JSDoc](#documentationjs-and-jsdoc)
19
19
-[English](#english)
20
20
-[Oxford Comma](#oxford-comma)
21
21
-[Wording](#wording)
@@ -44,11 +44,11 @@ Our community is large and diverse. Many people learn to code using p5.js, and a
44
44
45
45
## documentation.js and JSDoc
46
46
47
-
We use [documentation.js](https://documentation.js.org/) to generate the p5.js API documentation.
47
+
We use [documentation.js](https://documentation.js.org/) to generate the p5.js API documentation from [JSDoc](https://jsdoc.app/) comments in the p5.js source code.
48
48
49
-
TODO: add or link to instructions for generating and previewing the reference docs.
49
+
Refer to the [inline documentation guide](./contributing_to_the_p5js_reference.md) for more information on how to structure the documentation comments and what tags to use.
50
50
51
-
Refer to the [inline documentation guide](./contributing_to_the_p5js_reference.md) for more information.
51
+
It also discusses how to generate and preview the reference documentation to see your changes.
52
52
53
53
**[⬆ back to top](#table-of-contents)**
54
54
@@ -1265,25 +1265,30 @@ class Mover {
1265
1265
1266
1266
## Assets
1267
1267
1268
-
- Always load assets from a folder called "assets".
1268
+
Whether assets (such as images, fonts, sound files, etc) are being used in the descriptions or code examples of the reference documentation, or in tutorials, the same rules apply:
1269
1269
1270
-
> Why? It models good project organization. It's also required for assets to load on the p5.js website. Place assets in the following folders to include them in our online documentation:
0 commit comments