blob: 958fed99fd6d39ab513ae98d527d7d9169c94d7e [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
153Simple tables are supported with column alignment. The first line is
154the header row and subsequent lines are data rows:
155
156```
157| Food | Calories | Tasty? |
158|-------|---------:|:------:|
159| Apple | 95 | Yes |
160| Pear | 102 | Yes |
161| Hay | 977 | |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800162```
163
164will render as:
165
166| Food | Calories | Tasty? |
167|-------|---------:|:------:|
168| Apple | 95 | Yes |
169| Pear | 102 | Yes |
170| Hay | 977 | |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800171
172Placing `:` in the separator line indicates how the column should be
173aligned. A colon on the left side is a **left-aligned** column; a
174colon on the right-most side is **right-aligned**; a colon on both
David Pursehousedea03ba2017-06-29 21:08:49 +0900175sides is **center-aligned**. If no alignment is specified, the column
176is aligned with the default for HTML `<td>` tags (left-aligned by
177default unless overridden by css).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800178
Shawn Pearcea5dad192015-02-20 16:46:35 -0800179Empty table cells are indicated by whitespace between the column
180dividers (`| |`) while multiple column cells omit the whitespace.
181
182### Emphasis
183
184Emphasize paragraph text with *italic* and **bold** styles. Either `_`
185or `*` can be used for italic (1 character) and bold text (2
186characters). This allows styles to be mixed within a statement:
187
188```
189Emphasize paragraph text with *italic* and **bold** text.
190
191**It is _strongly_ encouraged to review documentation for typos.**
192```
193
194**It is _strongly_ encouraged to review documentation for typos.**
195
196Emphasis within_words_is_ignored which helps write technical
197documentation. Literal \*bold* can be forced by prefixing the
198opening `*` with \ such as `\*bold*`.
199
200### Strikethrough
201
202Text can be ~~struck out~~ within a paragraph:
203
204```
205Text can be ~~struck out~~ within a paragraph.
206```
207
208Note two tildes are required (`~~`) on either side of the struck out
209section of text.
210
Shawn Pearcea5dad192015-02-20 16:46:35 -0800211### Blockquotes
212
213Blockquoted text can be used to stand off text obtained from
214another source:
215
216```
217Sir Winston Churchill once said:
218
219> A lie gets halfway around the world before the truth has a
220> chance to get its pants on.
221```
222
223renders as:
224
225Sir Winston Churchill once said:
226
227> A lie gets halfway around the world before the truth has a
228> chance to get its pants on.
229
230### Code (inline)
231
232Use `backticks` to markup inline code within a paragraph:
233
234```
235Use `backticks` to markup inline code within a paragraph.
236```
237
238### Code (blocks)
239
240Create a fenced code block using three backticks before and after a
241block of code, preceeded and followed by blank lines:
242
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700243````
244This is a simple hello world program in C:
245
246``` c
247#include <stdio.h>
248
249int main() {
250 printf("Hello, World.\n");
251 return 0;
252}
Shawn Pearcea5dad192015-02-20 16:46:35 -0800253```
Shawn Pearcea5dad192015-02-20 16:46:35 -0800254
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700255To compile it use `gcc hello.c`.
256````
Shawn Pearcea5dad192015-02-20 16:46:35 -0800257
258Text within a fenced code block is taken verbatim and is not
259processed for Markdown markup.
260
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700261Syntax highlighting can optionally be enabled for common languages
262by adding the language name in lowercase on the opening line.
263Supported languages include:
264
265|||---||| 2,2,2,2,4
266
267#### Scripting
268* bash, sh
269* lua
270* perl
271* python, py
272* ruby
273* tcl
274
Andrew Bonventre4434b802015-09-29 12:27:56 -0400275#### Web
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700276* css
277* dart
278* html
279* javascript, js
280* json
281
282#### Compiled
283* basic, vb
284* c
285* cpp (C++)
286* go
287* java
288* pascal
289* scala
290
291#### Markup
292* tex, latex
293* wiki
294* xml
295* xquery
296* xsl
297* yaml
298
299#### Other
300* clj (Clojure)
301* erlang
302* hs (Haskell)
303* lisp
304* [llvm](http://llvm.org/docs/LangRef.html)
305* matlab
306* ml (OCaml, SML, F#)
307* r
308* [rd](http://cran.r-project.org/doc/manuals/R-exts.html)
309* rust
310* sql
311* vhdl
312|||---|||
313
Shawn Pearcea5dad192015-02-20 16:46:35 -0800314### Horizontal rules
315
316A horizontal rule can be inserted using GitHub style `--` surrounded
317by blank lines. Alternatively repeating `-` or `*` and space on a
318line will also create a horizontal rule:
319
320```
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700321---
Shawn Pearcea5dad192015-02-20 16:46:35 -0800322
323- - - -
324
325* * * *
326```
327
328### Links
329
330Wrap text in `[brackets]` and the link destination in parens
331`(http://...)` such as:
332
333```
334Visit [this site](http://example.com/) for more examples.
335```
336
337Links can also use references to obtain URLs from elsewhere in the
338same document. This style can be useful if the same URL needs to be
339mentioned multiple times, is too long to cleanly place within text,
340or the link is within a table cell:
341
342```
343Search for [markdown style][1] examples.
344
345[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
346```
347
348References can be simplified if the text alone is sufficient:
349
350```
351Visit [Google] to search the web.
352
353[Google]: https://www.google.com/
354```
355
356Automatic hyperlinking can be used where the link text should
357obviously also be the URL:
358
359```
360Use https://www.google.com/ to search the web.
361```
362
363Well formed URLs beginning with `https://`, `http://`, and `mailto:`
364are used as written for the link's destination. Malformed URLs may be
David Pursehoused40dbc22016-08-26 13:28:01 +0900365replaced with `about:invalid#zSoyz` to prevent browser evaluation of dangerous
Shawn Pearcea5dad192015-02-20 16:46:35 -0800366content.
367
368HTML escaping of URL characters such as `&` is handled internally by
369the parser/formatter. Documentation writers should insert the URL
370literally and allow the parser and formatter to make it HTML safe.
371
372Relative links such as `../src/api.md` are resolved relative to the
373current markdown's file path within the Git repository. Absolute
374links such as `/src/api.md` are resolved relative to the top of the
375enclosing Git repository, but within the same branch or Git commit.
376Links may point to any file in the repository. A link to a `*.md`
377file will present the rendered markdown, while a link to a source file
378will display the syntax highlighted source.
379
Shawn Pearce25d91962015-06-22 15:35:36 -0700380### Named anchors
381
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700382Explicit anchors can be inserted anywhere in the document using
383`<a name="tag"></a>` or `{#tag}`.
384
385Implicit anchors are automatically created for each
386[heading](#Headings). For example `## Section 1` will have
387the anchor `Section-1`.
388
389*** note
390*Anchor generation*
391
392* letters and digits, after removing accents (á → a)
David Pursehousef7680782015-06-24 02:52:12 +0000393* spaces are replaced with hyphens (`-`)
394* other characters are replaced with underscores (`_`)
395* runs of hyphens and underscores are collapsed
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700396***
397
398If a document contains the same named subsection under different
399parents the parent anchor will prefix the subsections to
400disambiguate. For example the following document will have anchors
401`Running-Format` and `Coding-Format` and `Libraries` as that subsection
402is unique:
403
404```
405## Running
406### Format
407## Coding
408### Format
409### Libraries
410```
411
412When placed in a section header the explicit anchor will override
413the automatic anchor. The following are identical and associate
414the anchor `live-examples` with the section header instead of the
415automaticly generated name `Examples`.
Shawn Pearce25d91962015-06-22 15:35:36 -0700416
417```
418## Examples {#live-examples}
419## Examples <a name="live-examples"></a>
420```
421
Shawn Pearcea5dad192015-02-20 16:46:35 -0800422### Images
423
424Similar to links but begin with `!` to denote an image reference:
425
426```
427![diffy the kung fu review cuckoo](http://commondatastorage.googleapis.com/gerrit-static/diffy-w200.png)
428```
429
430For images the text in brackets will be included as the alt text for
431screen readers.
432
433Well formed image URLs beginning with `https://` and `http://` will be
434used as written for the `<img src="...">` attribute. Malformed URLs
435will be replaced with a broken `data:` reference to prevent browsers
436from trying to load a bad destination.
437
438Relative and absolute links to image files within the Git repository
439(such as `../images/banner.png`) are resolved during rendering by
440inserting the base64 encoding of the image using a `data:` URI. Only
441PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`) and GIF (`*.gif`) image
442formats are supported when referenced from the Git repository.
443
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700444Unsupported extensions or files larger than [image size](#Image-size)
445limit (default 256K) will display a broken image.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800446
447*** note
448_Inline image caching_
449
450Gitiles allows browsers to locally cache rendered markdown pages.
451Cache invalidation is triggered by the markdown file being modified
452and having a different SHA-1 in Git. Inlined images may need a
453documentation file update to be refreshed when viewed through unstable
454URLs like `/docs/+/master/index.md`.
455***
456
457### HTML
458
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700459Most HTML tags are not supported. HTML will be dropped on the floor
460by the parser with no warnings, and no output from that section of the
Shawn Pearcea5dad192015-02-20 16:46:35 -0800461document.
462
Shawn Pearce12c8fab2016-05-15 16:55:21 -0700463There are small exceptions for `<br>`, `<hr>`, `<a name>` and
464`<iframe>` elements, see [named anchor](#Named-anchors) and
465[HTML IFrame](#HTML-IFrame).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800466
467## Markdown extensions
468
469Gitiles includes additional extensions to the Markdown language that
470make documentation writing for the web easier without using raw HTML.
471
472### Table of contents
473
474Place `[TOC]` surrounded by blank lines to insert a generated
475table of contents extracted from the H1, H2, and H3 headers
476used within the document:
477
478```
479# Title
480
481[TOC]
482
483## Section 1
484Blah blah...
485
486## Section 2
487Go on...
488```
489
490H1 headers are omitted from the table of contents if there is only one
491level one header present. This allows H1 to be used as the document
492title without creating an unnecessary entry in the table of contents.
493
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700494Anchors are automatically extracted from the headers, see
495[named anchors](#Named-anchors).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800496
497### Notification, aside, promotion blocks
498
499Similar to fenced code blocks these blocks start and end with `***`,
500are surrounded by blank lines, and include the type of block on the
501opening line.
502
503#### Note
504
505```
506*** note
507**Warning:** watch out for nested formatting.
508***
509```
510
511*** note
512**Warning:** watch out for nested formatting.
513***
514
515#### Aside
516
517```
518*** aside
519An aside can stand off less interesting text.
520***
521```
522
523*** aside
524An aside can stand off less interesting text.
525***
526
527#### Promo
528
529```
530*** promo
531Promotions can raise awareness of an important concept.
532***
533```
534
535*** promo
536Promotions can raise awareness of an important concept.
537***
538
539### Column layout
540
Shawn Pearceecddc612015-02-20 22:09:47 -0800541Gitiles markdown includes support for up to 12 columns of text across
542the width of the page. By default space is divided equally between
543the columns.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800544
545|||---|||
546#### Columns
547
548can save space.
549
550#### Prettify
551
552the page layout.
553
554*** promo
555#### Can be
556
557trendy.
558***
559|||---|||
560
561A column layout is denoted by a block starting and ending with the
562sequence `|||---|||`. Within the layout a new column is started for
563each header or note/promo/aside block and all text and formatting flow
564into that column until a new column is started.
565
566```
567|||---|||
568#### Columns
569
570can save space.
571
572#### Prettify
573
574the page layout.
575
576*** promo
577#### Can be
578
579trendy.
580***
581|||---|||
582```
583
Shawn Pearceecddc612015-02-20 22:09:47 -0800584Column spans can be specified on the first line as a comma separated
585list. In the example below the first column is 4 wide or 4/12ths of
586the page width, the second is 2 wide (or 2/12ths) and the final column
587is 6 wide (6/12ths or 50%) of the page.
588
589```
590|||---||| 4,2,6
591```
592
593An empty column can be inserted by prefixing its width with `:`,
594for example shifting content onto the right by padding 6 columns
595on the left:
596
597```
598|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700599#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800600|||---|||
601```
602
603renders as:
604
605|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700606#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800607|||---|||
608
Shawn Pearcea5dad192015-02-20 16:46:35 -0800609### HTML IFrame
610
611Although HTML is stripped the parser has special support for a limited
612subset of `<iframe>` elements:
613
614```
615<iframe src="https://example.com/embed" height="200px" width="400px"></iframe>
616```
617
618The parser allows whitespace including newlines between attributes,
619but strictly limits the supported attribute set to:
620
621src
622: An `https://` or `http://` URL of the page to embed inside of an
623iframe at this position in the document. Malformed URLs will cause
624the iframe to be silently dropped. _(required)_
625
626height
627: CSS pixel height such as `250px` defining the amount of vertical
628space to give to the embedded content. Only `px` units are supported;
629a malformed dimension will drop the iframe. _(required)_
630
631width
632: CSS pixel width such as `250px` or a precentage such as `80%`
633defining the amount of horizontal space to give to the embedded
634content. Only `px` units or `%` are supported; a malformed dimension
635will drop the iframe. _(required)_
636
637frameborder
638: By default a border is drawn around the iframe by the browser. The
639border can be hidden by adding `frameborder="0"` to the iframe tag.
640_(optional)_
641
642Embedded source URLs must also be whitelisted by the Gitiles
Shawn Pearce7e598e12016-08-26 08:51:12 -0700643[`markdown.allowiframe`](config.md#IFrames) configuration
David Pursehousebbcc5132016-08-26 13:26:13 +0900644variable.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800645
646## Site layout
647
648Gitiles includes additional support to create functional documentation
649sites served directly from Git repositories.
650
651### Navigation bar
652
653A top level navigation bar is automatically included on all pages if
654there is a `navbar.md` file present in the top of the repository.
655This file should be a simple bulleted list of links to include in the
656navigation bar.
657
658```
659* [Home](/index.md)
660* [Markdown](/docs/markdown.md)
661* [Configuration](/docs/configuration.md)
662```
663
664Links are resolved relative to the current page, not `navbar.md`.
665Links to other files within the repository should use absolute paths
666to ensure they are resolved correctly from any Markdown file within
667the repository.
668
669### Site title
670
Mike Colagrossoad028212016-01-20 23:25:59 -0700671A site-wide banner is displayed on all Markdown pages if `navbar.md`
672includes an H1 header. The text of the header is displayed on the
673left side of the banner.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800674
675```
676# Gitiles
677
678* [Home](/index.md)
679```
680
681### Site logo
682
683An optional logo image is displayed in the banner to the left of the
684site title if a `[logo]` reference exists in `navbar.md`. This image
685should be no taller than 45 px.
686
687```
688# Gitiles
689
690[logo]: /images/site_logo.png
691```
692
693See [images](#Images) above for acceptable URLs and how repository
694relative paths are handled by inline data URIs.
695
696### Home link
697
698Both the site logo (if present) and site title are wrapped in a link
699if the `[home]` reference is declared in `navbar.md`. This is
700typically also used in the outline for the navigation bar:
701
702```
703# Gitiles
704
705* [Home][home]
706* [Markdown](/docs/markdown.md)
707
708[home]: /index.md
709```
710
711### Page title
712
713Titles for pages are extracted from the first H1 heading appearing in
714the document. This is traditionally placed on the first line of the
715markdown file, e.g.:
716
717```
718# Markdown
719```
720
721The title is included in the HTML `<title>` element and also in the
722right side of the banner if `navbar.md` defines a
723[site title](#Site-title).
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700724
725## Configuration
726
727The `gitiles.config` file supporting the site contains several
David Pursehouse240fbff2016-08-25 09:58:15 +0900728configuration options that impact markdown rendering. Refer to the
729[configuration documentation](config.md#Markdown) for details.