Skip to content

Commit 6557952

Browse files
authored
Update style guide with more detail (#11094)
1 parent 15b8342 commit 6557952

1 file changed

Lines changed: 76 additions & 56 deletions

File tree

reference/docs-conceptual/community/contributing/powershell-style-guide.md

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
11
---
22
description: This article provides the rules of style for writing PowerShell documentation.
3-
ms.date: 11/14/2022
3+
ms.date: 05/09/2024
44
title: PowerShell-Docs style guide
55
---
66
# PowerShell-Docs style guide
77

88
This article provides style guidance specific to the PowerShell-Docs content. It builds on the
9-
information outlined in the [Overview][1].
9+
information outlined in the [Overview][10].
1010

1111
## Formatting command syntax elements
1212

13-
- Always use the full name for cmdlets and parameters. Avoid using aliases unless you're
14-
specifically demonstrating the alias.
15-
- Property, parameter, object, type names, class names, class methods should be **bold**.
16-
- Property and parameter values should be wrapped in backticks (`` ` ``).
17-
- When referring to types using the bracketed style, use backticks. For example:
18-
`[System.Io.FileInfo]`
19-
- Language keywords, cmdlet names, functions, variables, native EXEs, file paths, and inline syntax
20-
examples should be wrapped in backtick (`` ` ``) characters.
13+
Use the following rules to format elements of the PowerShell language when they are used in a
14+
sentence.
2115

22-
For example:
16+
- Always use the full name for cmdlets and parameters in the proper Pascal case
17+
- Only use an alias when you're specifically demonstrating the alias
18+
- PowerShell keywords and operators should be all lowercase
2319

24-
~~~markdown
25-
The following code uses `Get-ChildItem` to list the contents of `C:\Windows` and assigns
26-
the output to the `$files` variable.
20+
- The following items should be formatted using **bold** text:
21+
- Type names
22+
- Class names
23+
- Property names
24+
- Parameter names
25+
- By default, use the parameter without the hyphen prefix.
26+
- When illustrating the use of a parameter with the hyphen prefix, the parameter should be
27+
wrapped in backticks.
2728

28-
```powershell
29-
$files = Get-ChildItem C:\Windows
30-
```
31-
~~~
32-
33-
- PowerShell keywords and operators should be all lowercase
34-
35-
- Use proper (Pascal) casing for cmdlet names and parameters
36-
37-
- When referring to a parameter by name, the name should be **bold**. When illustrating the use of
38-
a parameter with the hyphen prefix, the parameter should be wrapped in backticks. For example:
29+
For example:
3930

4031
```markdown
4132
The parameter's name is **Name**, but it's typed as `-Name` when used on the command
4233
line as a parameter.
4334
```
4435

45-
- When showing example usage of an external command, the example should be wrapped in backticks.
46-
Always include the file extension in the native command. For example:
36+
- The following items should be formatted using backticks (`` ` ``):
37+
- Property and parameter values
38+
- Type names that use the bracketed style - For example: `[System.Io.FileInfo]`
39+
- Referring to characters by name. For example: Use the asterisk character (`*`) to as a wildcard.
40+
- Language keywords and operators
41+
- Cmdlet, function, and script names
42+
- Command and parameter aliases
43+
- Method names - For example: The `ToString()` method returns a string representation of the
44+
object
45+
- Variables
46+
- Native commands
47+
- File and directory paths
48+
- Inline command syntax examples - See [Markdown for code samples][04]
49+
50+
This example show some backtick examples:
51+
52+
~~~markdown
53+
The following code uses `Get-ChildItem` to list the contents of `C:\Windows` and assigns
54+
the output to the `$files` variable.
55+
56+
```powershell
57+
$files = Get-ChildItem C:\Windows
58+
```
59+
~~~
60+
61+
This examples shows command syntax inline:
4762

4863
```markdown
4964
To start the spooler service on a remote computer named DC01, you type:
@@ -71,7 +86,7 @@ The code fence markers must be on their own line before and after the code sampl
7186
marker may have an optional language label. The language label enables syntax highlighting on the
7287
rendered webpage.
7388

74-
For a full list of supported language tags, see [Fenced code blocks][2] in the centralized
89+
For a full list of supported language tags, see [Fenced code blocks][01] in the centralized
7590
contributor guide.
7691

7792
Publishing also adds a **Copy** button that can copy the contents of the code block to the
@@ -111,12 +126,14 @@ for (<init>; <condition>; <repeat>)
111126

112127
### Illustrative examples
113128

114-
Illustrative examples are used to explain a PowerShell concept. They aren't meant to be copied and
115-
pasted for execution. These are most commonly used for simple examples that are easy to understand.
116-
The code block can include the PowerShell prompt and example output.
129+
Illustrative examples are used to explain a PowerShell concept. In general you should
130+
[Avoid using PowerShell prompts in examples][03]. However, illustrative examples aren't meant to be
131+
copied and pasted for execution. These are most commonly used for simple examples that are easy to
132+
understand. The code block can include the PowerShell prompt and example output.
117133

118134
Here's a simple example illustrating the PowerShell comparison operators. In this case, we don't
119-
intend the reader to copy and run this example.
135+
intend the reader to copy and run this example. Notice that this example uses `PS>` as a simplified
136+
prompt string.
120137

121138
~~~markdown
122139
```powershell
@@ -180,9 +197,9 @@ Cmdlet Unprotect-CmsMessage 3.0.0.0 Microsoft.PowerShell.Securit
180197
```
181198
~~~
182199

183-
The **Output** code label isn't an official "language" supported by the syntax highlighting system.
184-
However, this label is useful because our publishing system adds the "Output" label to the code box
185-
frame on the web page. The "Output" code box has no syntax highlighting.
200+
The `Output` code label isn't an official _language_ supported by the syntax highlighting system.
201+
However, this label is useful because our publishing system adds the **Output** label to the code
202+
box frame on the web page. The **Output** code box has no syntax highlighting.
186203

187204
## Coding style rules
188205

@@ -191,7 +208,7 @@ frame on the web page. The "Output" code box has no syntax highlighting.
191208
Avoid using line continuation characters (`` ` ``) in PowerShell code examples. These are hard to
192209
see and can cause problems if there are extra spaces at the end of the line.
193210

194-
- Use PowerShell [splatting][3] to reduce line length for cmdlets that have several parameters.
211+
- Use PowerShell [splatting][02] to reduce line length for cmdlets that have several parameters.
195212
- Take advantage of PowerShell's natural line break opportunities, like after pipe (`|`) characters,
196213
opening braces (`{`), parentheses (`(`), and brackets (`[`).
197214

@@ -225,7 +242,7 @@ GameConfigStore GameDVR_Enabled : 1
225242
### Don't use aliases in examples
226243

227244
Use the full name of all cmdlets and parameters unless you're specifically documenting the alias.
228-
Cmdlet and parameter names must use the proper [Pascal-cased][4] names.
245+
Cmdlet and parameter names must use the proper [Pascal-cased][06] names.
229246

230247
### Using parameters in examples
231248

@@ -234,23 +251,24 @@ example, even if the parameter is positional. This reduces the chance of confusi
234251

235252
## Formatting cmdlet reference articles
236253

237-
Cmdlet reference articles have a specific structure. This structure is defined by [PlatyPS][5].
254+
Cmdlet reference articles have a specific structure. This structure is defined by [PlatyPS][07].
238255
PlatyPS generates the cmdlet help for PowerShell modules in Markdown. After editing the Markdown
239256
files, PlatyPS is used create the MAML help files used by the `Get-Help` cmdlet.
240257

241-
PlatyPS has a schema that expects a specific structure for cmdlet reference. The
242-
[platyPS.schema.md][6] document attempts to describe this structure. Schema violations cause build
243-
errors that must be fixed before we can accept your contribution.
258+
PlatyPS has a schema that expects a specific structure for cmdlet reference. The PlatyPS
259+
[schema document][08] describes this structure. Schema violations cause build errors that must be
260+
fixed before we can accept your contribution.
244261

245-
- Don't remove any of the ATX header structures. PlatyPS expects a specific set of headers.
246-
- The **Input type** and **Output type** headers must have a type. If the cmdlet doesn't take input
247-
or return a value, then use the value `None`.
262+
- Don't remove any of the ATX header structures. PlatyPS expects a specific set of headers in a
263+
specific order.
264+
- The H2 **INPUTS** and **OUTPUTS** headers must have an H3 type. If the cmdlet doesn't take input
265+
or return a value, then use the value `None` for the H3.
248266
- Inline code spans can be used in any paragraph.
249267
- Fenced code blocks are only allowed in the **EXAMPLES** section.
250268

251269
In the PlatyPS schema, **EXAMPLES** is an H2 header. Each example is an H3 header. Within an
252-
example, the schema doesn't allow code blocks to be separated by paragraphs. The schema allows the
253-
following structure:
270+
example, the schema doesn't allow code blocks to be separated by paragraphs. The schema only allows
271+
the following structure:
254272

255273
```
256274
### Example X - Title sentence
@@ -283,7 +301,7 @@ Get-Command -ListImported
283301

284302
## Formatting About_ files
285303

286-
`About_*` files are written in Markdown but are shipped as plain text files. We use [Pandoc][7] to
304+
`About_*` files are written in Markdown but are shipped as plain text files. We use [Pandoc][09] to
287305
convert the Markdown to plain text. `About_*` files are formatted for the best compatibility across
288306
all versions of PowerShell and with the publishing tools.
289307

@@ -310,14 +328,16 @@ Basic formatting guidelines:
310328

311329
## Next steps
312330

313-
[Editorial checklist][8]
331+
[Editorial checklist][05]
314332

315333
<!-- link references -->
316-
[1]: overview.md#get-started-writing-docs
317-
[2]: /contribute/code-in-docs#inline-code-blocks
318-
[3]: /powershell/module/microsoft.powershell.core/about/about_splatting
319-
[4]: https://en.wikipedia.org/wiki/PascalCase
320-
[5]: https://github.com/powershell/platyps
321-
[6]: https://github.com/PowerShell/platyPS/blob/master/platyPS.schema.md
322-
[7]: https://pandoc.org
323-
[8]: editorial-checklist.md
334+
[01]: /contribute/code-in-docs#inline-code-blocks
335+
[02]: /powershell/module/microsoft.powershell.core/about/about_splatting
336+
[03]: #avoid-using-powershell-prompts-in-examples
337+
[04]: #markdown-for-code-samples
338+
[05]: editorial-checklist.md
339+
[06]: https://en.wikipedia.org/wiki/PascalCase
340+
[07]: https://github.com/powershell/platyps
341+
[08]: https://github.com/PowerShell/platyPS/blob/master/platyPS.schema.md
342+
[09]: https://pandoc.org
343+
[10]: overview.md#get-started-writing-docs

0 commit comments

Comments
 (0)