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