blob: 4c763884a0b529590e66f02983b63008b1ae7508 [file] [log] [blame] [view]
Shawn Pearcea5dad192015-02-20 16:46:35 -08001# Markdown
2
Han-Wen Nienhuys7144d602017-01-17 12:49:04 +01003The [Gitiles](https://gerrit.googlesource.com/gitiles/) source browser
Shawn Pearcea5dad192015-02-20 16:46:35 -08004automatically renders `*.md` Markdown files into HTML for simplified
5documentation.
6
7[TOC]
8
9## Access controls
10
11Access controls for documentation is identical to source code.
12
13Documentation stored with source files shares the same permissions.
14Documentation stored in a separate Git repository can use different
15access controls. If Gerrit Code Review is being used, branch level
16read permissions can be used to grant or restrict access to any
17documentation branches.
18
19## READMEs
20
21Files named `README.md` are automatically displayed below the file's
22directory listing. For the top level directory this mirrors the
23standard [GitHub](https://github.com/) presentation.
24
25*** promo
26README.md files are meant to provide orientation for developers
27browsing the repository, especially first-time users.
28***
29
30We recommend that Git repositories have an up-to-date top-level
31`README.md` file.
32
33## Markdown syntax
34
35Gitiles supports the core Markdown syntax described in
36[Markdown Basics]. Additional extensions are supported
37to more closely match [GitHub Flavored Markdown] and
38simplify documentation writing.
39
40[Markdown Basics]: http://daringfireball.net/projects/markdown/basics
41[GitHub Flavored Markdown]: https://help.github.com/articles/github-flavored-markdown/
42
43### Paragraphs
44
45Paragraphs are one or more lines of consecutive text, followed by
46one or more blank lines. Line breaks within a paragraph are ignored
47by the parser, allowing authors to line-wrap text at any comfortable
48column width.
49
50```
51Documentation writing can be fun and profitable
52by helping users to learn and solve problems.
53
54After documentation is written, it needs to be published on the
55web where it can be easily accessed for reading.
56```
57
58### Headings
59
60Headings can be indicated by starting the line with one or more `#`
61marks. The number of `#` used determines the depth of the heading in
62the document outline. Headings 1 through 6 (`######`) are supported.
63
64```
65# A level one (H1) heading
66## A level two (H2) heading
67### A level three (H3) heading
68```
69
70Headings can also use the less popular two line `======` and `------`
71forms to create H1 and H2 level headers:
72
73```
74A first level header
75====================
76
77A second level header
78---------------------
79```
80
81This form is discouraged as maintaining the length of the `===` or
82`---` lines to match the preceding line can be tedious work that is
83unnecessary with the `#` headers.
84
85### Lists
86
87A bullet list:
88
89```
90* Fruit
91 * Orange
92 * Pear
93* Cake
94```
95
96will render into HTML as:
97
98* Fruit
99 * Orange
100 * Pear
101* Cake
102
103The second level items (above Orange, Pear) must be indented with more
104spaces than the item they are nested under. Above 2 spaces were used.
Shannon Woods7ea71122015-11-05 16:05:05 -0500105Additionally, the entire list must be preceded and followed by a blank
106line.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800107
108A numbered list:
109
110```
1111. Fruit
112 1. Orange
113 2. Pear
1145. Cake
115```
116
117will render into HTML as:
118
1191. Fruit
120 1. Orange
121 2. Pear
1225. Cake
123
124List items will be renumbered sequentially by the browser, which is
125why `5` above displays as `2`. Even with this feature it is a good
126idea to maintain list item numbers in the source Markdown to simplify
127reading the source file.
128
129Like bullet lists, numbered lists can be nested by using more leading
130space than the prior list item.
131
David Pursehouse31468362016-10-04 14:48:28 +0900132Paragraphs can be properly nested within lists by indenting with at
133least 2 leading spaces:
134
135```
1361. Fruit
137
138 In botany, a fruit is the seed-bearing structure in flowering
139 plants.
140
141 In common language usage, "fruit" normally means the fleshy
142 seed-associated structures of a plant that are sweet or sour, and
143 edible in the raw state, such as apples, bananas, grapes, lemons,
144 oranges, and strawberries.
145
1462. Cake
147
148 The cake is a lie.
149```
150
Shawn Pearcea5dad192015-02-20 16:46:35 -0800151### Tables
152
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700153Requires `markdown.tables` to be true (default).
154
Shawn Pearcea5dad192015-02-20 16:46:35 -0800155Simple tables are supported with column alignment. The first line is
156the header row and subsequent lines are data rows:
157
158```
159| Food | Calories | Tasty? |
160|-------|---------:|:------:|
161| Apple | 95 | Yes |
162| Pear | 102 | Yes |
163| Hay | 977 | |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800164```
165
166will render as:
167
168| Food | Calories | Tasty? |
169|-------|---------:|:------:|
170| Apple | 95 | Yes |
171| Pear | 102 | Yes |
172| Hay | 977 | |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800173
174Placing `:` in the separator line indicates how the column should be
175aligned. A colon on the left side is a **left-aligned** column; a
176colon on the right-most side is **right-aligned**; a colon on both
David Pursehousedea03ba2017-06-29 21:08:49 +0900177sides is **center-aligned**. If no alignment is specified, the column
178is aligned with the default for HTML `<td>` tags (left-aligned by
179default unless overridden by css).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800180
Shawn Pearcea5dad192015-02-20 16:46:35 -0800181Empty table cells are indicated by whitespace between the column
182dividers (`| |`) while multiple column cells omit the whitespace.
183
184### Emphasis
185
186Emphasize paragraph text with *italic* and **bold** styles. Either `_`
187or `*` can be used for italic (1 character) and bold text (2
188characters). This allows styles to be mixed within a statement:
189
190```
191Emphasize paragraph text with *italic* and **bold** text.
192
193**It is _strongly_ encouraged to review documentation for typos.**
194```
195
196**It is _strongly_ encouraged to review documentation for typos.**
197
198Emphasis within_words_is_ignored which helps write technical
199documentation. Literal \*bold* can be forced by prefixing the
200opening `*` with \ such as `\*bold*`.
201
202### Strikethrough
203
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700204Requires `markdown.strikethrough` to be true (default).
205
Shawn Pearcea5dad192015-02-20 16:46:35 -0800206Text can be ~~struck out~~ within a paragraph:
207
208```
209Text can be ~~struck out~~ within a paragraph.
210```
211
212Note two tildes are required (`~~`) on either side of the struck out
213section of text.
214
Shawn Pearcea5dad192015-02-20 16:46:35 -0800215### Blockquotes
216
217Blockquoted text can be used to stand off text obtained from
218another source:
219
220```
221Sir Winston Churchill once said:
222
223> A lie gets halfway around the world before the truth has a
224> chance to get its pants on.
225```
226
227renders as:
228
229Sir Winston Churchill once said:
230
231> A lie gets halfway around the world before the truth has a
232> chance to get its pants on.
233
234### Code (inline)
235
236Use `backticks` to markup inline code within a paragraph:
237
238```
239Use `backticks` to markup inline code within a paragraph.
240```
241
242### Code (blocks)
243
244Create a fenced code block using three backticks before and after a
245block of code, preceeded and followed by blank lines:
246
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700247````
248This is a simple hello world program in C:
249
250``` c
251#include <stdio.h>
252
253int main() {
254 printf("Hello, World.\n");
255 return 0;
256}
Shawn Pearcea5dad192015-02-20 16:46:35 -0800257```
Shawn Pearcea5dad192015-02-20 16:46:35 -0800258
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700259To compile it use `gcc hello.c`.
260````
Shawn Pearcea5dad192015-02-20 16:46:35 -0800261
262Text within a fenced code block is taken verbatim and is not
263processed for Markdown markup.
264
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700265Syntax highlighting can optionally be enabled for common languages
266by adding the language name in lowercase on the opening line.
267Supported languages include:
268
269|||---||| 2,2,2,2,4
270
271#### Scripting
272* bash, sh
273* lua
274* perl
275* python, py
276* ruby
277* tcl
278
Andrew Bonventre4434b802015-09-29 12:27:56 -0400279#### Web
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700280* css
281* dart
282* html
283* javascript, js
284* json
285
286#### Compiled
287* basic, vb
288* c
289* cpp (C++)
290* go
291* java
292* pascal
293* scala
294
295#### Markup
296* tex, latex
297* wiki
298* xml
299* xquery
300* xsl
301* yaml
302
303#### Other
304* clj (Clojure)
305* erlang
306* hs (Haskell)
307* lisp
308* [llvm](http://llvm.org/docs/LangRef.html)
309* matlab
310* ml (OCaml, SML, F#)
311* r
312* [rd](http://cran.r-project.org/doc/manuals/R-exts.html)
313* rust
314* sql
315* vhdl
316|||---|||
317
Shawn Pearcea5dad192015-02-20 16:46:35 -0800318### Horizontal rules
319
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700320If `markdown.ghthematicbreak` is true, a horizontal rule can be
321inserted using GitHub style `--` surrounded by blank lines.
322Alternatively repeating `-` or `*` and space on a line will also
323create a horizontal rule:
Shawn Pearcea5dad192015-02-20 16:46:35 -0800324
325```
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700326---
Shawn Pearcea5dad192015-02-20 16:46:35 -0800327
328- - - -
329
330* * * *
331```
332
333### Links
334
335Wrap text in `[brackets]` and the link destination in parens
336`(http://...)` such as:
337
338```
339Visit [this site](http://example.com/) for more examples.
340```
341
342Links can also use references to obtain URLs from elsewhere in the
343same document. This style can be useful if the same URL needs to be
344mentioned multiple times, is too long to cleanly place within text,
345or the link is within a table cell:
346
347```
348Search for [markdown style][1] examples.
349
350[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
351```
352
353References can be simplified if the text alone is sufficient:
354
355```
356Visit [Google] to search the web.
357
358[Google]: https://www.google.com/
359```
360
361Automatic hyperlinking can be used where the link text should
362obviously also be the URL:
363
364```
365Use https://www.google.com/ to search the web.
366```
367
368Well formed URLs beginning with `https://`, `http://`, and `mailto:`
369are used as written for the link's destination. Malformed URLs may be
David Pursehoused40dbc22016-08-26 13:28:01 +0900370replaced with `about:invalid#zSoyz` to prevent browser evaluation of dangerous
Shawn Pearcea5dad192015-02-20 16:46:35 -0800371content.
372
373HTML escaping of URL characters such as `&` is handled internally by
374the parser/formatter. Documentation writers should insert the URL
375literally and allow the parser and formatter to make it HTML safe.
376
377Relative links such as `../src/api.md` are resolved relative to the
378current markdown's file path within the Git repository. Absolute
379links such as `/src/api.md` are resolved relative to the top of the
380enclosing Git repository, but within the same branch or Git commit.
381Links may point to any file in the repository. A link to a `*.md`
382file will present the rendered markdown, while a link to a source file
383will display the syntax highlighted source.
384
Shawn Pearce25d91962015-06-22 15:35:36 -0700385### Named anchors
386
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700387Explicit anchors can be inserted anywhere in the document using
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700388`<a name="tag"></a>`, or `{#tag}` if `markdown.namedanchor` is true.
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700389
390Implicit anchors are automatically created for each
391[heading](#Headings). For example `## Section 1` will have
392the anchor `Section-1`.
393
394*** note
395*Anchor generation*
396
397* letters and digits, after removing accents (á → a)
David Pursehousef7680782015-06-24 02:52:12 +0000398* spaces are replaced with hyphens (`-`)
399* other characters are replaced with underscores (`_`)
400* runs of hyphens and underscores are collapsed
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700401***
402
403If a document contains the same named subsection under different
404parents the parent anchor will prefix the subsections to
405disambiguate. For example the following document will have anchors
406`Running-Format` and `Coding-Format` and `Libraries` as that subsection
407is unique:
408
409```
410## Running
411### Format
412## Coding
413### Format
414### Libraries
415```
416
417When placed in a section header the explicit anchor will override
418the automatic anchor. The following are identical and associate
419the anchor `live-examples` with the section header instead of the
420automaticly generated name `Examples`.
Shawn Pearce25d91962015-06-22 15:35:36 -0700421
422```
423## Examples {#live-examples}
424## Examples <a name="live-examples"></a>
425```
426
Shawn Pearcea5dad192015-02-20 16:46:35 -0800427### Images
428
429Similar to links but begin with `!` to denote an image reference:
430
431```
432![diffy the kung fu review cuckoo](http://commondatastorage.googleapis.com/gerrit-static/diffy-w200.png)
433```
434
435For images the text in brackets will be included as the alt text for
436screen readers.
437
438Well formed image URLs beginning with `https://` and `http://` will be
439used as written for the `<img src="...">` attribute. Malformed URLs
440will be replaced with a broken `data:` reference to prevent browsers
441from trying to load a bad destination.
442
443Relative and absolute links to image files within the Git repository
444(such as `../images/banner.png`) are resolved during rendering by
445inserting the base64 encoding of the image using a `data:` URI. Only
James Zernb592dbe2020-09-24 13:08:39 -0700446PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`), GIF (`*.gif`) and WebP (`*.webp`)
447image formats are supported when referenced from the Git repository.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800448
Tom Fuke43c3f7f2020-12-10 09:37:59 +0000449Unsupported extensions or files larger than [image size](config.md#Image-size)
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700450limit (default 256K) will display a broken image.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800451
452*** note
453_Inline image caching_
454
455Gitiles allows browsers to locally cache rendered markdown pages.
456Cache invalidation is triggered by the markdown file being modified
457and having a different SHA-1 in Git. Inlined images may need a
458documentation file update to be refreshed when viewed through unstable
459URLs like `/docs/+/master/index.md`.
460***
461
462### HTML
463
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700464Most HTML tags are not supported. HTML will be dropped on the floor
465by the parser with no warnings, and no output from that section of the
Shawn Pearcea5dad192015-02-20 16:46:35 -0800466document.
467
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700468If `markdown.safehtml` is true there are small exceptions for `<br>`,
469`<hr>`, `<a name>` and `<iframe>` elements, see [named anchor](#Named-anchors)
470and [HTML IFrame](#HTML-IFrame).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800471
472## Markdown extensions
473
474Gitiles includes additional extensions to the Markdown language that
475make documentation writing for the web easier without using raw HTML.
476
477### Table of contents
478
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700479Requires `markdown.toc` to be true.
480
Shawn Pearcea5dad192015-02-20 16:46:35 -0800481Place `[TOC]` surrounded by blank lines to insert a generated
482table of contents extracted from the H1, H2, and H3 headers
483used within the document:
484
485```
486# Title
487
488[TOC]
489
490## Section 1
491Blah blah...
492
493## Section 2
494Go on...
495```
496
497H1 headers are omitted from the table of contents if there is only one
498level one header present. This allows H1 to be used as the document
499title without creating an unnecessary entry in the table of contents.
500
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700501Anchors are automatically extracted from the headers, see
502[named anchors](#Named-anchors).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800503
504### Notification, aside, promotion blocks
505
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700506Requires `markdown.blocknote` to be true.
507
Shawn Pearcea5dad192015-02-20 16:46:35 -0800508Similar to fenced code blocks these blocks start and end with `***`,
509are surrounded by blank lines, and include the type of block on the
510opening line.
511
512#### Note
513
514```
515*** note
516**Warning:** watch out for nested formatting.
517***
518```
519
520*** note
521**Warning:** watch out for nested formatting.
522***
523
524#### Aside
525
526```
527*** aside
528An aside can stand off less interesting text.
529***
530```
531
532*** aside
533An aside can stand off less interesting text.
534***
535
536#### Promo
537
538```
539*** promo
540Promotions can raise awareness of an important concept.
541***
542```
543
544*** promo
545Promotions can raise awareness of an important concept.
546***
547
548### Column layout
549
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700550Requires `markdown.multicolumn` to be true.
551
Shawn Pearceecddc612015-02-20 22:09:47 -0800552Gitiles markdown includes support for up to 12 columns of text across
553the width of the page. By default space is divided equally between
554the columns.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800555
556|||---|||
557#### Columns
558
559can save space.
560
561#### Prettify
562
563the page layout.
564
565*** promo
566#### Can be
567
568trendy.
569***
570|||---|||
571
572A column layout is denoted by a block starting and ending with the
573sequence `|||---|||`. Within the layout a new column is started for
574each header or note/promo/aside block and all text and formatting flow
575into that column until a new column is started.
576
577```
578|||---|||
579#### Columns
580
581can save space.
582
583#### Prettify
584
585the page layout.
586
587*** promo
588#### Can be
589
590trendy.
591***
592|||---|||
593```
594
Shawn Pearceecddc612015-02-20 22:09:47 -0800595Column spans can be specified on the first line as a comma separated
596list. In the example below the first column is 4 wide or 4/12ths of
597the page width, the second is 2 wide (or 2/12ths) and the final column
598is 6 wide (6/12ths or 50%) of the page.
599
600```
601|||---||| 4,2,6
602```
603
604An empty column can be inserted by prefixing its width with `:`,
605for example shifting content onto the right by padding 6 columns
606on the left:
607
608```
609|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700610#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800611|||---|||
612```
613
614renders as:
615
616|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700617#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800618|||---|||
619
Shawn Pearcea5dad192015-02-20 16:46:35 -0800620### HTML IFrame
621
Shawn Pearceb55cf2b2017-06-29 21:56:37 -0700622Requires `markdown.safehtml` to be true (default).
623
Shawn Pearcea5dad192015-02-20 16:46:35 -0800624Although HTML is stripped the parser has special support for a limited
625subset of `<iframe>` elements:
626
627```
628<iframe src="https://example.com/embed" height="200px" width="400px"></iframe>
629```
630
631The parser allows whitespace including newlines between attributes,
632but strictly limits the supported attribute set to:
633
634src
635: An `https://` or `http://` URL of the page to embed inside of an
636iframe at this position in the document. Malformed URLs will cause
637the iframe to be silently dropped. _(required)_
638
639height
640: CSS pixel height such as `250px` defining the amount of vertical
641space to give to the embedded content. Only `px` units are supported;
642a malformed dimension will drop the iframe. _(required)_
643
644width
645: CSS pixel width such as `250px` or a precentage such as `80%`
646defining the amount of horizontal space to give to the embedded
647content. Only `px` units or `%` are supported; a malformed dimension
648will drop the iframe. _(required)_
649
650frameborder
651: By default a border is drawn around the iframe by the browser. The
652border can be hidden by adding `frameborder="0"` to the iframe tag.
653_(optional)_
654
655Embedded source URLs must also be whitelisted by the Gitiles
Shawn Pearce7e598e12016-08-26 08:51:12 -0700656[`markdown.allowiframe`](config.md#IFrames) configuration
David Pursehousebbcc5132016-08-26 13:26:13 +0900657variable.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800658
659## Site layout
660
661Gitiles includes additional support to create functional documentation
662sites served directly from Git repositories.
663
664### Navigation bar
665
666A top level navigation bar is automatically included on all pages if
667there is a `navbar.md` file present in the top of the repository.
668This file should be a simple bulleted list of links to include in the
669navigation bar.
670
671```
672* [Home](/index.md)
673* [Markdown](/docs/markdown.md)
674* [Configuration](/docs/configuration.md)
675```
676
677Links are resolved relative to the current page, not `navbar.md`.
678Links to other files within the repository should use absolute paths
679to ensure they are resolved correctly from any Markdown file within
680the repository.
681
682### Site title
683
Mike Colagrossoad028212016-01-20 23:25:59 -0700684A site-wide banner is displayed on all Markdown pages if `navbar.md`
685includes an H1 header. The text of the header is displayed on the
686left side of the banner.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800687
688```
689# Gitiles
690
691* [Home](/index.md)
692```
693
694### Site logo
695
696An optional logo image is displayed in the banner to the left of the
697site title if a `[logo]` reference exists in `navbar.md`. This image
698should be no taller than 45 px.
699
700```
701# Gitiles
702
703[logo]: /images/site_logo.png
704```
705
706See [images](#Images) above for acceptable URLs and how repository
707relative paths are handled by inline data URIs.
708
709### Home link
710
711Both the site logo (if present) and site title are wrapped in a link
712if the `[home]` reference is declared in `navbar.md`. This is
713typically also used in the outline for the navigation bar:
714
715```
716# Gitiles
717
718* [Home][home]
719* [Markdown](/docs/markdown.md)
720
721[home]: /index.md
722```
723
724### Page title
725
726Titles for pages are extracted from the first H1 heading appearing in
727the document. This is traditionally placed on the first line of the
728markdown file, e.g.:
729
730```
731# Markdown
732```
733
734The title is included in the HTML `<title>` element and also in the
735right side of the banner if `navbar.md` defines a
736[site title](#Site-title).
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700737
738## Configuration
739
740The `gitiles.config` file supporting the site contains several
David Pursehouse240fbff2016-08-25 09:58:15 +0900741configuration options that impact markdown rendering. Refer to the
742[configuration documentation](config.md#Markdown) for details.