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