blob: 7ee70d94582a5d5315deb6caef5e211549b5134d [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.
105
106A numbered list:
107
108```
1091. Fruit
110 1. Orange
111 2. Pear
1125. Cake
113```
114
115will render into HTML as:
116
1171. Fruit
118 1. Orange
119 2. Pear
1205. Cake
121
122List items will be renumbered sequentially by the browser, which is
123why `5` above displays as `2`. Even with this feature it is a good
124idea to maintain list item numbers in the source Markdown to simplify
125reading the source file.
126
127Like bullet lists, numbered lists can be nested by using more leading
128space than the prior list item.
129
130### Tables
131
132Simple tables are supported with column alignment. The first line is
133the header row and subsequent lines are data rows:
134
135```
136| Food | Calories | Tasty? |
137|-------|---------:|:------:|
138| Apple | 95 | Yes |
139| Pear | 102 | Yes |
140| Hay | 977 | |
141[Food and its benefits]
142```
143
144will render as:
145
146| Food | Calories | Tasty? |
147|-------|---------:|:------:|
148| Apple | 95 | Yes |
149| Pear | 102 | Yes |
150| Hay | 977 | |
151[Food and its benefits]
152
153Placing `:` in the separator line indicates how the column should be
154aligned. A colon on the left side is a **left-aligned** column; a
155colon on the right-most side is **right-aligned**; a colon on both
156sides is **center-aligned**.
157
158An optional table title can be placed under the table in brackets
159(`[...]`).
160
161Cells may span multiple columns and include formatting accepted within
162paragraphs such as emphasis, images or links:
163
164| | Grouping ||
165| First Header | Second Header | Third Header |
166| ------------ | :-----------: | -----------: |
167| Content | *Long Cell* ||
168| Content | **Cell 2** | Cell 3 |
169
170the above table was created by:
171
172```
173| | Grouping ||
174| First Header | Second Header | Third Header |
175| ------------ | :-----------: | -----------: |
176| Content | *Long Cell* ||
177| Content | **Cell 2** | Cell 3 |
178```
179
180Empty table cells are indicated by whitespace between the column
181dividers (`| |`) while multiple column cells omit the whitespace.
182
183### Emphasis
184
185Emphasize paragraph text with *italic* and **bold** styles. Either `_`
186or `*` can be used for italic (1 character) and bold text (2
187characters). This allows styles to be mixed within a statement:
188
189```
190Emphasize paragraph text with *italic* and **bold** text.
191
192**It is _strongly_ encouraged to review documentation for typos.**
193```
194
195**It is _strongly_ encouraged to review documentation for typos.**
196
197Emphasis within_words_is_ignored which helps write technical
198documentation. Literal \*bold* can be forced by prefixing the
199opening `*` with \ such as `\*bold*`.
200
201### Strikethrough
202
203Text can be ~~struck out~~ within a paragraph:
204
205```
206Text can be ~~struck out~~ within a paragraph.
207```
208
209Note two tildes are required (`~~`) on either side of the struck out
210section of text.
211
212### Smart quotes
213
214'Single', "double" and <<double angle>> quotes in paragraph text are
215replaced with smart quotes. Apostrophes (this doc's text), ellipses
216("...") and dashes ("--" and "---") are also replaced with HTML
217entities to make the documentation appear typeset.
218
219To force use of the ASCII characters prefix with \, for example `\'`
220for a \' normal single quote.
221
222### Blockquotes
223
224Blockquoted text can be used to stand off text obtained from
225another source:
226
227```
228Sir Winston Churchill once said:
229
230> A lie gets halfway around the world before the truth has a
231> chance to get its pants on.
232```
233
234renders as:
235
236Sir Winston Churchill once said:
237
238> A lie gets halfway around the world before the truth has a
239> chance to get its pants on.
240
241### Code (inline)
242
243Use `backticks` to markup inline code within a paragraph:
244
245```
246Use `backticks` to markup inline code within a paragraph.
247```
248
249### Code (blocks)
250
251Create a fenced code block using three backticks before and after a
252block of code, preceeded and followed by blank lines:
253
254```
255 This is a simple hello world program in C:
256
257 ```
258 #include <stdio.h>
259
260 int main() {
261 printf("Hello, World.\n");
262 return 0;
263 }
264 ```
265
266 To compile it use `gcc hello.c`.
267```
268
269Text within a fenced code block is taken verbatim and is not
270processed for Markdown markup.
271
272### Horizontal rules
273
274A horizontal rule can be inserted using GitHub style `--` surrounded
275by blank lines. Alternatively repeating `-` or `*` and space on a
276line will also create a horizontal rule:
277
278```
279--
280
281- - - -
282
283* * * *
284```
285
286### Links
287
288Wrap text in `[brackets]` and the link destination in parens
289`(http://...)` such as:
290
291```
292Visit [this site](http://example.com/) for more examples.
293```
294
295Links can also use references to obtain URLs from elsewhere in the
296same document. This style can be useful if the same URL needs to be
297mentioned multiple times, is too long to cleanly place within text,
298or the link is within a table cell:
299
300```
301Search for [markdown style][1] examples.
302
303[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
304```
305
306References can be simplified if the text alone is sufficient:
307
308```
309Visit [Google] to search the web.
310
311[Google]: https://www.google.com/
312```
313
314Automatic hyperlinking can be used where the link text should
315obviously also be the URL:
316
317```
318Use https://www.google.com/ to search the web.
319```
320
321Well formed URLs beginning with `https://`, `http://`, and `mailto:`
322are used as written for the link's destination. Malformed URLs may be
323replaced with `#zSoyz` to prevent browser evaluation of dangerous
324content.
325
326HTML escaping of URL characters such as `&` is handled internally by
327the parser/formatter. Documentation writers should insert the URL
328literally and allow the parser and formatter to make it HTML safe.
329
330Relative links such as `../src/api.md` are resolved relative to the
331current markdown's file path within the Git repository. Absolute
332links such as `/src/api.md` are resolved relative to the top of the
333enclosing Git repository, but within the same branch or Git commit.
334Links may point to any file in the repository. A link to a `*.md`
335file will present the rendered markdown, while a link to a source file
336will display the syntax highlighted source.
337
338### Images
339
340Similar to links but begin with `!` to denote an image reference:
341
342```
343![diffy the kung fu review cuckoo](http://commondatastorage.googleapis.com/gerrit-static/diffy-w200.png)
344```
345
346For images the text in brackets will be included as the alt text for
347screen readers.
348
349Well formed image URLs beginning with `https://` and `http://` will be
350used as written for the `<img src="...">` attribute. Malformed URLs
351will be replaced with a broken `data:` reference to prevent browsers
352from trying to load a bad destination.
353
354Relative and absolute links to image files within the Git repository
355(such as `../images/banner.png`) are resolved during rendering by
356inserting the base64 encoding of the image using a `data:` URI. Only
357PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`) and GIF (`*.gif`) image
358formats are supported when referenced from the Git repository.
359
360The Gitiles `markdown.imageLimit` configuration variable sets an upper
361byte limit for inserted image files. Unsupported extensions or files
362larger than this threshold (default 256K) will display a broken image.
363
364*** note
365_Inline image caching_
366
367Gitiles allows browsers to locally cache rendered markdown pages.
368Cache invalidation is triggered by the markdown file being modified
369and having a different SHA-1 in Git. Inlined images may need a
370documentation file update to be refreshed when viewed through unstable
371URLs like `/docs/+/master/index.md`.
372***
373
374### HTML
375
376HTML tags are not supported. HTML will be dropped on the floor by the
377parser with no warnings, and no output from that section of the
378document.
379
380There is a small exception for the `<iframe>` element, see
381[HTML IFrame](#HTML-IFrame) below.
382
383## Markdown extensions
384
385Gitiles includes additional extensions to the Markdown language that
386make documentation writing for the web easier without using raw HTML.
387
388### Table of contents
389
390Place `[TOC]` surrounded by blank lines to insert a generated
391table of contents extracted from the H1, H2, and H3 headers
392used within the document:
393
394```
395# Title
396
397[TOC]
398
399## Section 1
400Blah blah...
401
402## Section 2
403Go on...
404```
405
406H1 headers are omitted from the table of contents if there is only one
407level one header present. This allows H1 to be used as the document
408title without creating an unnecessary entry in the table of contents.
409
410Element ids to create anchors are automatically generated by filtering
411the text of the header. For example above `Section 1` will have the
412anchor `#Section-1`. To create an anchor letters and digits are used
413(after removing accents), spaces are replaced with `-`, and other
414characters are replaced with `_`. Changing the title of a section
415will (most likely) change its anchor.
416
417### Notification, aside, promotion blocks
418
419Similar to fenced code blocks these blocks start and end with `***`,
420are surrounded by blank lines, and include the type of block on the
421opening line.
422
423#### Note
424
425```
426*** note
427**Warning:** watch out for nested formatting.
428***
429```
430
431*** note
432**Warning:** watch out for nested formatting.
433***
434
435#### Aside
436
437```
438*** aside
439An aside can stand off less interesting text.
440***
441```
442
443*** aside
444An aside can stand off less interesting text.
445***
446
447#### Promo
448
449```
450*** promo
451Promotions can raise awareness of an important concept.
452***
453```
454
455*** promo
456Promotions can raise awareness of an important concept.
457***
458
459### Column layout
460
Shawn Pearceecddc612015-02-20 22:09:47 -0800461Gitiles markdown includes support for up to 12 columns of text across
462the width of the page. By default space is divided equally between
463the columns.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800464
465|||---|||
466#### Columns
467
468can save space.
469
470#### Prettify
471
472the page layout.
473
474*** promo
475#### Can be
476
477trendy.
478***
479|||---|||
480
481A column layout is denoted by a block starting and ending with the
482sequence `|||---|||`. Within the layout a new column is started for
483each header or note/promo/aside block and all text and formatting flow
484into that column until a new column is started.
485
486```
487|||---|||
488#### Columns
489
490can save space.
491
492#### Prettify
493
494the page layout.
495
496*** promo
497#### Can be
498
499trendy.
500***
501|||---|||
502```
503
Shawn Pearceecddc612015-02-20 22:09:47 -0800504Column spans can be specified on the first line as a comma separated
505list. In the example below the first column is 4 wide or 4/12ths of
506the page width, the second is 2 wide (or 2/12ths) and the final column
507is 6 wide (6/12ths or 50%) of the page.
508
509```
510|||---||| 4,2,6
511```
512
513An empty column can be inserted by prefixing its width with `:`,
514for example shifting content onto the right by padding 6 columns
515on the left:
516
517```
518|||---||| :6,3
519# Right
520|||---|||
521```
522
523renders as:
524
525|||---||| :6,3
526# Right
527|||---|||
528
Shawn Pearcea5dad192015-02-20 16:46:35 -0800529### HTML IFrame
530
531Although HTML is stripped the parser has special support for a limited
532subset of `<iframe>` elements:
533
534```
535<iframe src="https://example.com/embed" height="200px" width="400px"></iframe>
536```
537
538The parser allows whitespace including newlines between attributes,
539but strictly limits the supported attribute set to:
540
541src
542: An `https://` or `http://` URL of the page to embed inside of an
543iframe at this position in the document. Malformed URLs will cause
544the iframe to be silently dropped. _(required)_
545
546height
547: CSS pixel height such as `250px` defining the amount of vertical
548space to give to the embedded content. Only `px` units are supported;
549a malformed dimension will drop the iframe. _(required)_
550
551width
552: CSS pixel width such as `250px` or a precentage such as `80%`
553defining the amount of horizontal space to give to the embedded
554content. Only `px` units or `%` are supported; a malformed dimension
555will drop the iframe. _(required)_
556
557frameborder
558: By default a border is drawn around the iframe by the browser. The
559border can be hidden by adding `frameborder="0"` to the iframe tag.
560_(optional)_
561
562Embedded source URLs must also be whitelisted by the Gitiles
563`markdown.allowiframe` configuration variable.
564
565## Site layout
566
567Gitiles includes additional support to create functional documentation
568sites served directly from Git repositories.
569
570### Navigation bar
571
572A top level navigation bar is automatically included on all pages if
573there is a `navbar.md` file present in the top of the repository.
574This file should be a simple bulleted list of links to include in the
575navigation bar.
576
577```
578* [Home](/index.md)
579* [Markdown](/docs/markdown.md)
580* [Configuration](/docs/configuration.md)
581```
582
583Links are resolved relative to the current page, not `navbar.md`.
584Links to other files within the repository should use absolute paths
585to ensure they are resolved correctly from any Markdown file within
586the repository.
587
588### Site title
589
590A site wide banner is displayed on all Markdown pages if `navbar.md`
591includes a H1 header. The text of the header is display on the left
592side of the banner.
593
594```
595# Gitiles
596
597* [Home](/index.md)
598```
599
600### Site logo
601
602An optional logo image is displayed in the banner to the left of the
603site title if a `[logo]` reference exists in `navbar.md`. This image
604should be no taller than 45 px.
605
606```
607# Gitiles
608
609[logo]: /images/site_logo.png
610```
611
612See [images](#Images) above for acceptable URLs and how repository
613relative paths are handled by inline data URIs.
614
615### Home link
616
617Both the site logo (if present) and site title are wrapped in a link
618if the `[home]` reference is declared in `navbar.md`. This is
619typically also used in the outline for the navigation bar:
620
621```
622# Gitiles
623
624* [Home][home]
625* [Markdown](/docs/markdown.md)
626
627[home]: /index.md
628```
629
630### Page title
631
632Titles for pages are extracted from the first H1 heading appearing in
633the document. This is traditionally placed on the first line of the
634markdown file, e.g.:
635
636```
637# Markdown
638```
639
640The title is included in the HTML `<title>` element and also in the
641right side of the banner if `navbar.md` defines a
642[site title](#Site-title).