Skip to content

Commit b31b833

Browse files
Update md guidance to include all current recommendations (#11046)
* Update md guidance to include all current recommendations * Apply suggestions from code review Co-authored-by: Mike F. Robbins <[email protected]> * Feedback edits --------- Co-authored-by: Mike F. Robbins <[email protected]>
1 parent 1807cd8 commit b31b833

1 file changed

Lines changed: 143 additions & 65 deletions

File tree

reference/docs-conceptual/community/contributing/general-markdown.md

Lines changed: 143 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,97 @@
11
---
22
description: This article provides specific guidance for using Markdown in our documentation.
3-
ms.date: 07/26/2022
3+
ms.date: 04/23/2024
44
title: Markdown best practices
55
---
66
# Markdown best practices
77

88
This article provides specific guidance for using Markdown in our documentation. This is not a
9-
tutorial for Markdown, but list specific rules and best practice for Markdown in the PowerShell
10-
docs. If you need a tutorial for Markdown, see this [Markdown cheatsheet][1].
9+
tutorial for Markdown, but lists specific rules and best practices for Markdown in the PowerShell
10+
docs. If you need a tutorial for Markdown, see this [Markdown cheatsheet][12].
1111

12-
## Markdown specifics
13-
14-
The Microsoft Open Publishing System (OPS) that builds our documentation uses [markdig][2] to
12+
The Microsoft Open Publishing System (OPS) that builds our documentation uses [markdig][06] to
1513
process the Markdown documents. Markdig parses the documents based on the rules of the latest
16-
[CommonMark][3] specification.
14+
[CommonMark][10] specification. OPS follows the CommonMark specification and adds some extensions
15+
for platform-specific features, such as tables and alerts.
1716

18-
The CommonMark spec is much stricter about the construction of some Markdown elements. Pay close
19-
attention to the details provided in this document.
17+
The CommonMark specification is much stricter about the construction of some Markdown elements. Pay
18+
close attention to the details provided in this document.
2019

21-
We use the [markdownlint][4] extension in VS Code to enforce our style and formatting rules. This
20+
We use the [markdownlint][08] extension in VS Code to enforce our style and formatting rules. This
2221
extension is installed as part of the **Learn Authoring Pack**.
2322

24-
### Blank lines, spaces, and tabs
23+
## Blank lines, spaces, and tabs
2524

2625
Blank lines also signal the end of a block in Markdown.
2726

2827
- There should be a single blank between Markdown blocks of different types -- for example, between
2928
a paragraph and a list or header.
30-
- Don't use more than one blank line. Multiple blank lines render as a single blank line in HTML
31-
and serve no purpose.
29+
- Don't use more than one blank line. Multiple blank lines render as a single blank line in HTML,
30+
therefore the extra blank lines are unnecessary.
3231
- Within a code block, consecutive blank lines break the code block.
3332

3433
Spacing is significant in Markdown.
3534

3635
- Remove extra spaces at the end of lines. Trailing spaces can change how Markdown renders.
37-
- Always uses spaces instead of hard tabs.
36+
- Always use spaces instead of tabs (hard tabs).
3837

39-
### Titles and headings
38+
## Titles and headings
4039

41-
Only use [ATX headings][5] (# style, as opposed to `=` or `-` style headers).
40+
Only use [ATX headings][07] (`#` style, as opposed to `=` or `-` style headers).
4241

4342
- Use sentence case - only proper nouns and the first letter of a title or header should be
4443
capitalized
4544
- There must be a single space between the `#` and the first letter of the heading
4645
- Headings should be surrounded by a single blank line
4746
- Only one H1 per document
4847
- Header levels should increment by one -- don't skip levels
48+
- Limit depth to H3 or H4
4949
- Avoid using bold or other markup in headers
5050

51-
### Limit line length to 100 characters
51+
## Limit line length to 100 characters
5252

5353
This applies to conceptual articles and cmdlet reference. Limiting the line length improves the
54-
readability of git diffs and history. It also makes it easier for other writers to make
54+
readability of `git` diffs and history. It also makes it easier for other writers to make
5555
contributions.
5656

57-
Use the [Reflow Markdown][6] extension in VS Code to reflow paragraphs to fit the prescribed line
57+
Use the [Reflow Markdown][09] extension in VS Code to reflow paragraphs to fit the prescribed line
5858
length.
5959

60-
About_topics are limited to 80 characters. For more specific information, see
61-
[Formatting About_ files][7].
60+
Some content types can't be easily reflowed. For example, the code inside of code blocks may also be
61+
difficult to reflow, depending on the content and the code language. And you can't reflow a table.
62+
In these cases, use your best judgment to keep the content as close to the 100-character limit as
63+
possible.
64+
65+
## Emphasis
66+
67+
For emphasis, Markdown supports bold and italics. Markdown allows you to use either `*` or `_` to
68+
mark the emphasis. However, to be consistent and show intent:
69+
70+
- Use `**` for bold
71+
- Use `_` for italics
6272

63-
### Lists
73+
Following this pattern makes it easier for others to understand the intent of the markup when there
74+
is a mix of bold and italics in a document.
75+
76+
## Lists
6477

6578
If your list has multiple sentences or paragraphs, consider using a sublevel header rather than a
6679
list.
6780

6881
List should be surrounded by a single blank line.
6982

70-
#### Unordered lists
83+
### Unordered lists
7184

7285
- Don't end list items with a period unless they contain multiple sentences.
73-
- Use the hyphen character (`-`) for list item bullets. This avoids confusion with bold or italic
74-
markup that uses the asterisk (`*`).
86+
- Use the hyphen character (`-`) for list item bullets. This avoids confusion with emphasis markup
87+
that uses the asterisk (`*`).
7588
- To include a paragraph or other elements under a bullet item, insert a line break and align
7689
indentation with the first character after the bullet.
7790

7891
For example:
7992

80-
```markdown
81-
This is a list that contain child elements under a bullet item.
93+
```Markdown
94+
This is a list that contains child elements under a bullet item.
8295

8396
- First bullet item
8497

@@ -105,17 +118,17 @@ This is a list that contains child elements under a bullet item.
105118
- Second bullet item
106119
- Third bullet item
107120

108-
#### Ordered lists
121+
### Ordered lists
109122

110-
- All items in a numbered listed should use the number `1.` rather than incrementing each item.
123+
- All items in a numbered list should use the number `1.` rather than incrementing each item.
111124
- Markdown rendering increments the value automatically.
112125
- This makes reordering items easier and standardizes the indentation of subordinate content.
113126
- To include a paragraph or other elements under a numbered item, align indentation with the first
114127
character after the item number.
115128

116129
For example:
117130

118-
```markdown
131+
```Markdown
119132
1. For the first element, insert a single space after the 1. Long sentences should be wrapped to the
120133
next line and must line up with the first character after the numbered list marker.
121134

@@ -137,11 +150,11 @@ The resulting Markdown is rendered as follows:
137150

138151
1. The next numbered item starts here.
139152

140-
### Images
153+
## Images
141154

142155
The syntax to include an image is:
143156

144-
```markdown
157+
```Markdown
145158
![[alt text]](<folderPath>)
146159

147160
Example:
@@ -158,17 +171,17 @@ image.
158171
images for that article to that new folder.
159172
- Don't share images between articles.
160173
- If an image is used by multiple articles, each folder must have a copy of that image.
161-
- This prevents a change to an image in one article affecting another article.
174+
- This prevents a change to an image in one article from affecting another article.
162175

163176
The following image file types are supported: `*.png`, `*.gif`, `*.jpeg`, `*.jpg`, `*.svg`
164177

165-
### Markdown extensions supported by Open Publishing
178+
## Markdown extension - Alert boxes
166179

167-
The [Learn Authoring Pack][8] contains tools that support features unique to our publishing
180+
The [Learn Authoring Pack][01] contains tools that support features unique to our publishing
168181
system. Alerts are a Markdown extension to create blockquotes that render with colors and icons
169182
highlighting the significance of the content. The following alert types are supported:
170183

171-
```markdown
184+
```Markdown
172185
> [!NOTE]
173186
> Information the user should notice even if skimming.
174187
@@ -212,61 +225,88 @@ Warning block
212225
> [!WARNING]
213226
> Dangerous certain consequences of an action.
214227
215-
### Hyperlinks
228+
## Markdown extension - Tables
229+
230+
A table is an arrangement of data with rows and columns, consisting of a single header row, a
231+
delimiter row separating the header from the data, and zero or more data rows.
232+
233+
Each row consists of cells containing arbitrary text separated by pipes (`|`). A leading and
234+
trailing pipe is also recommended for clarity. Spaces between pipes and cell content are trimmed.
235+
Block-level elements can't be inserted in a table. All content of a row must be on a single line.
236+
237+
The delimiter row consists of cells whose only content are hyphens (`-`), and optionally, a leading
238+
or trailing colon (`:`), or both, to indicate left, right, or center alignment respectively.
239+
240+
For small tables, consider using a list instead. Lists are easier to maintain and read, can be
241+
reflowed to fit within the 100-character line limit, and are more accessible for users that use
242+
screen readers for visual assistance.
243+
244+
For more information, see _Tables_ section of [Markdown reference for Microsoft Learn][05].
245+
246+
## Hyperlinks
216247

217248
- Hyperlinks must use Markdown syntax `[friendlyname](url-or-path)`.
218-
- [Link references][9] are supported.
219249
- The publishing system supports three types of links:
220250
- URL links
221251
- File links
222252
- Cross-reference links
223253
- All URLs to external websites should use HTTPS unless that isn't valid for the target site.
224254
- Links must have a friendly name, usually the title of the linked article
225-
- Don't use backticks, bold, or other markup inside the brackets of a hyperlink.
226-
- Bare URLs may be used when you're documenting a specific URI and must be enclosed in backticks.
255+
- Avoid using backticks, bold, or other markup inside the brackets of a hyperlink.
256+
- Bare URLs may be used when you're documenting a specific URI but must be enclosed in backticks.
227257
For example:
228258

229-
```markdown
259+
```Markdown
230260
By default, if you don't specify this parameter, the DMTF standard resource URI
231261
`http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/` is used and the class name is appended to it.
232262
```
263+
- Use [link references][11] where allowed. Link references within paragraphs make the paragraphs
264+
more readable.
265+
266+
Link references divide a Markdown link into two parts:
233267

234-
#### URL-type Links
268+
- the link reference - `[friendlyname][id]`
269+
- the link definition - `[id]: url-or-path`
270+
271+
### URL-type Links
235272

236273
- URL links to other articles on `learn.microsoft.com` must use site-relative paths. The simplest
237-
way to create a relative link is to copy the URL from your browser then remove
274+
way to create a site-relative link is to copy the URL from your browser then remove
238275
`https://learn.microsoft.com/en-us` from the value you paste into markdown.
239-
- Don't include locales in URLs on Microsoft properties (remove `/en-us` from URL).
276+
- Don't include locales in URLs on Microsoft properties (remove `/en-us` from URL) or Wikipedia
277+
links.
240278
- Remove any unnecessary query parameters from the URL. Examples that should be removed:
241279
- `?view=powershell-5.1` - used to link to a specific version of PowerShell
242280
- `?redirectedfrom=MSDN` - added to the URL when you get redirected from an old article to its new
243281
location
244282
- If you need to link to a specific version of a document, you must add the `&preserve-view=true`
245283
parameter to the query string. For example: `?view=powershell-5.1&preserve-view=true`
246-
- URL links don't contain file extensions (for example, no `.md`)
284+
- On Microsoft sites, URL links don't contain file extensions (for example, no `.md`)
247285

248-
#### File-type links
286+
### File-type links
249287

250288
- A file link is used to link from one reference article to another, or from one conceptual
251-
article to another. If you need to link from a conceptual article to a reference article you must
252-
use a URL link.
289+
article to another in the same docset.
290+
- If you need to link from a conceptual article to a reference article you must use a URL link.
291+
- If you need to link to an article in another docset or across repositories you must use a URL
292+
link.
253293
- Use relative filepaths (for example: `../folder/file.md`)
254294
- All file paths use forward-slash (`/`) characters
255295
- Include the file extension (for example, `.md`)
256296

257-
#### Cross-reference links
297+
### Cross-reference links
258298

259299
Cross-reference links are a special feature supported by the publishing system. You can use
260300
cross-reference links in conceptual articles to link to .NET API or cmdlet reference.
261301

262-
- For links to .NET API reference, see [Use links in documentation][10] in the central Contributor
302+
- For links to .NET API reference, see [Use links in documentation][03] in the central Contributor
263303
Guide.
264304
- Links to cmdlet reference have the following format: `xref:<module-name>.<cmdlet-name>`. For
265305
example, to link to the `Get-Content` cmdlet in the **Microsoft.PowerShell.Management** module.
266306

267307
`[Get-Content](xref:Microsoft.PowerShell.Management.Get-Content)`
268308

269-
#### Deep linking
309+
### Deep linking
270310

271311
Deep linking is allowed on both URL and file links.
272312

@@ -275,22 +315,60 @@ Deep linking is allowed on both URL and file links.
275315
- `[about_Splatting](about_Splatting.md#splatting-with-arrays)`
276316
- `[custom key bindings](https://code.visualstudio.com/docs/getstarted/keybindings#_custom-keybindings-for-refactorings)`
277317

278-
For more information, see [Use links in documentation][11].
318+
For more information, see [Use links in documentation][02].
319+
320+
## Code spans
321+
322+
Code spans are used for inline code snippets within a paragraph. Use single backticks to indicate a
323+
code span. For example:
324+
325+
```Markdown
326+
PowerShell cmdlet names use the `Verb-Noun` naming convention.
327+
```
328+
329+
This example renders as:
330+
331+
PowerShell cmdlet names use the `Verb-Noun` naming convention.
332+
333+
## Code blocks
334+
335+
Code blocks are used for command examples, multi-line code samples, query languages, and outputs.
336+
There are two ways to indicate a section of text in an article file is a code block: by fencing it
337+
in triple-backticks (` ``` `) or by indenting it.
338+
339+
Never use indentation because it's too easy to get wrong and it may be difficult for another writer to
340+
understand your intent when they need to edit your article.
341+
342+
Fenced code blocks can include an optional tag that indicates the language syntax contained in the
343+
block. The publishing platform supports a list of [language tags][04]. The language tag is used to
344+
provide syntax highlighting when the article is rendered on the webpage. The language tag is not
345+
case-sensitive, but you should use lowercase except for a few special cases.
346+
347+
- Code fences without tags can be used for syntax blocks or other types of content where syntax
348+
highlighting is not required.
349+
- When showing output from a command, use a tagged code fence with the language tag `Output`. The
350+
rendered box is labeled as **Output** and doesn't have syntax highlighting.
351+
- If the output is in a specific supported language, use the appropriate language tag. For example,
352+
many commands output JSON, so use the `json` tag.
353+
- If you use an unsupported language tag, the code block will render without syntax highlighting.
354+
The language tag becomes the label for the rendered code box on the webpage. Capitalize the tag so
355+
that the label is capitalized on the webpage.
279356

280357
## Next steps
281358

282-
[PowerShell style guide][12]
359+
[PowerShell style guide][13]
283360

284361
<!-- link references -->
285-
[1]: https://www.markdownguide.org/cheat-sheet/
286-
[2]: https://github.com/lunet-io/markdig
287-
[3]: https://spec.commonmark.org/
288-
[4]: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
289-
[5]: https://github.github.com/gfm/#atx-headings
290-
[6]: https://marketplace.visualstudio.com/items?itemName=marvhen.reflow-markdown
291-
[7]: powershell-style-guide.md#formatting-about_-files
292-
[8]: /contribute/how-to-write-docs-auth-pack
293-
[9]: https://spec.commonmark.org/0.29/#link-reference-definitions
294-
[10]: /contribute/how-to-write-links#xref-cross-reference-links
295-
[11]: /contribute/how-to-write-links
296-
[12]: powershell-style-guide.md
362+
[01]: /contribute/content/how-to-write-docs-auth-pack
363+
[02]: /contribute/content/how-to-write-links
364+
[03]: /contribute/content/how-to-write-links#xref-cross-reference-links
365+
[04]: /contribute/content/code-in-docs#supported-languages
366+
[05]: /contribute/content/markdown-reference#tables
367+
[06]: https://github.com/lunet-io/markdig
368+
[07]: https://github.github.com/gfm/#atx-headings
369+
[08]: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
370+
[09]: https://marketplace.visualstudio.com/items?itemName=marvhen.reflow-markdown
371+
[10]: https://spec.commonmark.org/
372+
[11]: https://github.github.com/gfm/#reference-link
373+
[12]: https://www.markdownguide.org/cheat-sheet/
374+
[13]: powershell-style-guide.md

0 commit comments

Comments
 (0)