22
33These are the guidelines for writing Electron documentation.
44
5- ## Titles
5+ ## Headings
66
77* Each page must have a single ` # ` -level title at the top.
8- * Chapters in the same page must have ` ## ` -level titles .
9- * Sub-chapters need to increase the number of ` # ` in the title according to
8+ * Chapters in the same page must have ` ## ` -level headings .
9+ * Sub-chapters need to increase the number of ` # ` in the heading according to
1010 their nesting depth.
11- * All words in the page's title must be capitalized, except for conjunctions
12- like "of" and "and" .
13- * Only the first word of a chapter title must be capitalized.
11+ * The page's title must follow [ APA title case] [ title-case ] .
12+ * All chapters must follow [ APA sentence case] [ sentence-case ] .
1413
1514Using ` Quick Start ` as example:
1615
@@ -44,12 +43,20 @@ For API references, there are exceptions to this rule.
4443
4544## Markdown rules
4645
46+ This repository uses the [ ` markdownlint ` ] [ markdownlint ] package to enforce consistent
47+ Markdown styling. For the exact rules, see the ` .markdownlint.json ` file in the root
48+ folder.
49+
50+ There are a few style guidelines that aren't covered by the linter rules:
51+
52+ <!-- TODO(erickzhao): make sure this matches with the lint:markdownlint task-->
4753* Use ` sh ` instead of ` cmd ` in code blocks (due to the syntax highlighter).
48- * Lines should be wrapped at 80 columns.
54+ * Keep line lengths between 80 and 100 characters if possible for readability
55+ purposes.
4956* No nesting lists more than 2 levels (due to the markdown renderer).
5057* All ` js ` and ` javascript ` code blocks are linted with
5158[ standard-markdown] ( https://www.npmjs.com/package/standard-markdown ) .
52- * For unordered lists, use asterisks instead of dashes
59+ * For unordered lists, use asterisks instead of dashes.
5360
5461## Picking words
5562
@@ -60,14 +67,15 @@ For API references, there are exceptions to this rule.
6067
6168The following rules only apply to the documentation of APIs.
6269
63- ### Page title
70+ ### Title and description
6471
65- Each page must use the actual object name returned by ` require('electron') `
66- as the title, such as ` BrowserWindow ` , ` autoUpdater ` , and ` session ` .
72+ Each module's API doc must use the actual object name returned by ` require('electron') `
73+ as its title ( such as ` BrowserWindow ` , ` autoUpdater ` , and ` session ` ) .
6774
68- Under the page title must be a one-line description starting with ` > ` .
75+ Directly under the page title, add a one-line description of the module
76+ as a markdown quote (beginning with ` > ` ).
6977
70- Using ` session ` as example:
78+ Using the ` session ` module as an example:
7179
7280``` markdown
7381# session
@@ -99,14 +107,19 @@ Using `autoUpdater` as an example:
99107* API classes or classes that are part of modules must be listed under a
100108 ` ## Class: TheClassName ` chapter.
101109* One page can have multiple classes.
102- * Constructors must be listed with ` ### ` -level titles.
103- * [ Static Methods] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static ) must be listed under a ` ### Static Methods ` chapter.
104- * [ Instance Methods] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods ) must be listed under an ` ### Instance Methods ` chapter.
105- * All methods that have a return value must start their description with "Returns ` [TYPE] ` - Return description"
106- * If the method returns an ` Object ` , its structure can be specified using a colon followed by a newline then an unordered list of properties in the same style as function parameters.
110+ * Constructors must be listed with ` ### ` -level headings.
111+ * [ Static Methods] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static )
112+ must be listed under a ` ### Static Methods ` chapter.
113+ * [ Instance Methods] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods )
114+ must be listed under an ` ### Instance Methods ` chapter.
115+ * All methods that have a return value must start their description with
116+ "Returns ` [TYPE] ` - [ Return description] "
117+ * If the method returns an ` Object ` , its structure can be specified using a colon
118+ followed by a newline then an unordered list of properties in the same style as
119+ function parameters.
107120* Instance Events must be listed under an ` ### Instance Events ` chapter.
108121* Instance Properties must be listed under an ` ### Instance Properties ` chapter.
109- * Instance properties must start with "A [ Property Type] ..."
122+ * Instance Properties must start with "A [ Property Type] ..."
110123
111124Using the ` Session ` and ` Cookies ` classes as an example:
112125
@@ -142,7 +155,7 @@ Using the `Session` and `Cookies` classes as an example:
142155#### ` cookies.get(filter, callback) `
143156```
144157
145- ### Methods
158+ ### Methods and their arguments
146159
147160The methods chapter must be in the following form:
148161
@@ -155,8 +168,12 @@ The methods chapter must be in the following form:
155168...
156169```
157170
158- The title can be ` ### ` or ` #### ` -levels depending on whether it is a method of
159- a module or a class.
171+ #### Heading level
172+
173+ The heading can be ` ### ` or ` #### ` -levels depending on whether the method
174+ belongs to a module or a class.
175+
176+ #### Function signature
160177
161178For modules, the ` objectName ` is the module's name. For classes, it must be the
162179name of the instance of the class, and must not be the same as the module's
@@ -165,23 +182,33 @@ name.
165182For example, the methods of the ` Session ` class under the ` session ` module must
166183use ` ses ` as the ` objectName ` .
167184
168- The optional arguments are notated by square brackets ` [] ` surrounding the optional argument
169- as well as the comma required if this optional argument follows another
185+ Optional arguments are notated by square brackets ` [] ` surrounding the optional
186+ argument as well as the comma required if this optional argument follows another
170187argument:
171188
172- ``` sh
189+ ``` markdown
173190required[ , optional]
174191```
175192
176- Below the method is more detailed information on each of the arguments. The type
177- of argument is notated by either the common types:
193+ #### Argument descriptions
178194
179- * [ ` String ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String )
180- * [ ` Number ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number )
181- * [ ` Object ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object )
182- * [ ` Array ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array )
183- * [ ` Boolean ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean )
184- * Or a custom type like Electron's [ ` WebContent ` ] ( api/web-contents.md )
195+ More detailed information on each of the arguments is noted in an unordered list
196+ below the method. The type of argument is notated by either JavaScript primitives
197+ (e.g. ` String ` , ` Promise ` , or ` Object ` ), a custom API structure like Electron's
198+ [ ` Cookie ` ] ( api/structures/cookie.md ) , or the wildcard ` any ` .
199+
200+ If the argument is of type ` Array ` , use ` [] ` shorthand with the type of value
201+ inside the array (for example,` any[] ` or ` String[] ` ).
202+
203+ If the argument is of type ` Promise ` , parametrize the type with what the promise
204+ resolves to (for example, ` Promise<void> ` or ` Promise<String> ` ).
205+
206+ If an argument can be of multiple types, separate the types with ` | ` .
207+
208+ The description for ` Function ` type arguments should make it clear how it may be
209+ called and list the types of the parameters that will be passed to it.
210+
211+ #### Platform-specific functionality
185212
186213If an argument or a method is unique to certain platforms, those platforms are
187214denoted using a space-delimited italicized list following the datatype. Values
@@ -191,12 +218,6 @@ can be `macOS`, `Windows` or `Linux`.
191218* ` animate ` Boolean (optional) _ macOS_ _ Windows_ - Animate the thing.
192219```
193220
194- ` Array ` type arguments must specify what elements the array may include in
195- the description below.
196-
197- The description for ` Function ` type arguments should make it clear how it may be
198- called and list the types of the parameters that will be passed to it.
199-
200221### Events
201222
202223The events chapter must be in following form:
@@ -211,8 +232,8 @@ Returns:
211232...
212233```
213234
214- The title can be ` ### ` or ` #### ` -levels depending on whether it is an event of
215- a module or a class.
235+ The heading can be ` ### ` or ` #### ` -levels depending on whether the event
236+ belongs to a module or a class.
216237
217238The arguments of an event follow the same rules as methods.
218239
@@ -226,9 +247,13 @@ The properties chapter must be in following form:
226247...
227248```
228249
229- The title can be ` ### ` or ` #### ` -levels depending on whether it is a property of
230- a module or a class.
250+ The heading can be ` ### ` or ` #### ` -levels depending on whether the property
251+ belongs to a module or a class.
231252
232- ## Documentation Translations
253+ ## Documentation translations
233254
234255See [ electron/i18n] ( https://github.com/electron/i18n#readme )
256+
257+ [ title-case ] : https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case
258+ [ sentence-case ] : https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case
259+ [ markdownlint ] : https://github.com/DavidAnson/markdownlint
0 commit comments