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
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+54-4
Original file line number
Diff line number
Diff line change
@@ -42,12 +42,21 @@ On the other hand, we want to especially keep:
42
42
43
43
In between these clear-cut categories, there is some gray area. Please feel free to open an issue if you think something is being included that shouldn't be, or is being excluded but should be kept.
44
44
45
-
## Source formatting
45
+
## Style guide
46
46
47
-
Due to the long legacy of the existing text the guidelines below are not always applied. We do require that you apply the guidelines when making changes, though are happy to provide assistance if this proves to be a blocker to you.
47
+
The HTML Standard generally follows style conventions listed in the [Infra Standard](https://infra.spec.whatwg.org) and the [WHATWG style guide](https://whatwg.org/style-guide). Additionally, the HTML Standard follows some specific style conventions not captured by those documents, that we enumerate below.
48
+
49
+
Due to the long legacy of the existing text, these guidelines are not always applied. We do require that you apply the guidelines when making changes, though we are happy to provide assistance if this proves to be a blocker to you.
50
+
51
+
### Source formatting
52
+
53
+
54
+
#### Line wrapping length
48
55
49
56
Use a column width of 100 characters and add newlines where whitespace is used. (Emacs, set `fill-column` to `100`; in Vim, set `textwidth` to `100`; and in Sublime, set `wrap_width` to `100`. Alternatively, wrap the paragraph(s) with your changes with https://domenic.github.io/rewrapper/. Make sure that `column length to rewrap` is set to 100.)
50
57
58
+
#### Wrapping opportunities
59
+
51
60
Using newlines between "inline" element tag names and their content is forbidden. (This actually alters the content, by adding spaces.) That is,
52
61
```html
53
62
<dd><span>Parse error</span>. Create a new DOCTYPE token. Set its <idata-x="force-quirks
@@ -60,8 +69,14 @@ is fine and
60
69
```
61
70
is not.
62
71
63
-
Using newlines between attributes and inside attribute values that contain whitespace is allowed.
64
-
Always wrap after putting the maximum number of characters on a single line within these guidelines.
72
+
Using newlines between attributes and inside attribute values that contain whitespace is allowed. Always wrap after putting the maximum number of characters on a single line within these guidelines.
73
+
74
+
```html
75
+
<p>A <code>base</code> element that is the first <code>base</code> element with an <code
76
+
data-x="attr-base-href">href</code> content attribute <span>in a document tree</span> has a
77
+
```
78
+
79
+
### Element hierarchy
65
80
66
81
An `<li>` element always has a `<p>` element inside it, unless it's a child of `<ul class="brief">`.
67
82
@@ -93,3 +108,38 @@ is not indented, but
93
108
is.
94
109
95
110
End tags must not be omitted (except where it is consistent to do so) and attribute values must be quoted (use double quotes).
111
+
112
+
### Common mistakes around prose style
113
+
114
+
Most of the style conventions in this section are covered by Infra or the WHATWG style guide, but the editors often have to correct them in contributions anyway.
115
+
116
+
- Use the [algorithm declaration conventions](https://infra.spec.whatwg.org/#algorithm-declaration) in the Infra Standard.
117
+
-**"If foo, then bar"** instead of "If foo, bar". [Example](https://github.com/whatwg/html/pull/10269#discussion_r1568114777).
118
+
-**"Abort these steps" vs "return"**: Use "return" to exit a whole algorithm or method. Use "abort these steps" to terminate a set of substeps or [in parallel](https://html.spec.whatwg.org/C#in-parallel) steps and continue at the next step in the "outer" procedure. See examples in [this section on parallelism](https://html.spec.whatwg.org/C#parallelism) and elsewhere throughout the spec, as well as https://github.com/whatwg/infra/issues/258.
119
+
-**Usage of positional, optional, and named[^1] (i.e., linkable) parameters**. Follow the [algorithm parameter conventions](https://infra.spec.whatwg.org/#algorithm-params) in the Infra Standard. In particular, use named/linkable optional parameters in your algorithm declaration when callsites pass in values for them while omitting earlier-positioned optional parameters.
120
+
- When **nesting 3+ conditions** in a list, the style should look like so:
121
+
```html
122
+
<li><p>Foo.</p></li>
123
+
124
+
<li>
125
+
<p>If (all|any) of the following are true:</p>
126
+
127
+
<ulclass="brief">
128
+
<li><p>condition 1;</p></li>
129
+
130
+
<li><p>condition 2;</p></li>
131
+
132
+
<li><p>condition 3; (and|or)</p></li>
133
+
134
+
<li><p>condition 4,</p></li>
135
+
</ul>
136
+
137
+
<p>then…</p>
138
+
</li>
139
+
140
+
<li><p>Baz.</p></li>
141
+
```
142
+
-**Conjugate algorithm invocations inline** so they read more naturally in English, instead of more procedurally. For [example](https://github.com/whatwg/html/pull/9778#discussion_r1574075112), use `the result of <span data-x="get the popcorn">getting the popcorn</span>` instead of `the result of running <span>get the popcorn</span>`.
143
+
- Prefer American English to British English; see the [WHATWG style guide](https://whatwg.org/style-guide).
144
+
145
+
[^1]: For example, see parameters like https://html.spec.whatwg.org/C#navigation-referrer-policy, which are named/linkable parameters in an algorithm's declaration.
0 commit comments