blob: e1c6da35e194d48d990e15638c193a2be28dfa40 [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 | |
143[Food and its benefits]
144```
145
146will render as:
147
148| Food | Calories | Tasty? |
149|-------|---------:|:------:|
150| Apple | 95 | Yes |
151| Pear | 102 | Yes |
152| Hay | 977 | |
153[Food and its benefits]
154
155Placing `:` in the separator line indicates how the column should be
156aligned. A colon on the left side is a **left-aligned** column; a
157colon on the right-most side is **right-aligned**; a colon on both
158sides is **center-aligned**.
159
160An optional table title can be placed under the table in brackets
161(`[...]`).
162
163Cells may span multiple columns and include formatting accepted within
164paragraphs such as emphasis, images or links:
165
Andrew Bonventre4434b802015-09-29 12:27:56 -0400166| | Grouping ||
167| First Header | Second Header | Third Header |
168| ------------ | :-----------: | -----------: |
169| Content | *Long Cell* ||
170| Content | **Cell 2** | Cell 3 |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800171
172the above table was created by:
173
174```
Andrew Bonventre4434b802015-09-29 12:27:56 -0400175| | Grouping ||
176| First Header | Second Header | Third Header |
177| ------------ | :-----------: | -----------: |
178| Content | *Long Cell* ||
179| Content | **Cell 2** | Cell 3 |
Shawn Pearcea5dad192015-02-20 16:46:35 -0800180```
181
182Empty table cells are indicated by whitespace between the column
183dividers (`| |`) while multiple column cells omit the whitespace.
184
185### Emphasis
186
187Emphasize paragraph text with *italic* and **bold** styles. Either `_`
188or `*` can be used for italic (1 character) and bold text (2
189characters). This allows styles to be mixed within a statement:
190
191```
192Emphasize paragraph text with *italic* and **bold** text.
193
194**It is _strongly_ encouraged to review documentation for typos.**
195```
196
197**It is _strongly_ encouraged to review documentation for typos.**
198
199Emphasis within_words_is_ignored which helps write technical
200documentation. Literal \*bold* can be forced by prefixing the
201opening `*` with \ such as `\*bold*`.
202
203### Strikethrough
204
205Text can be ~~struck out~~ within a paragraph:
206
207```
208Text can be ~~struck out~~ within a paragraph.
209```
210
211Note two tildes are required (`~~`) on either side of the struck out
212section of text.
213
214### Smart quotes
215
216'Single', "double" and <<double angle>> quotes in paragraph text are
217replaced with smart quotes. Apostrophes (this doc's text), ellipses
218("...") and dashes ("--" and "---") are also replaced with HTML
219entities to make the documentation appear typeset.
220
221To force use of the ASCII characters prefix with \, for example `\'`
222for a \' normal single quote.
223
224### Blockquotes
225
226Blockquoted text can be used to stand off text obtained from
227another source:
228
229```
230Sir Winston Churchill once said:
231
232> A lie gets halfway around the world before the truth has a
233> chance to get its pants on.
234```
235
236renders as:
237
238Sir Winston Churchill once said:
239
240> A lie gets halfway around the world before the truth has a
241> chance to get its pants on.
242
243### Code (inline)
244
245Use `backticks` to markup inline code within a paragraph:
246
247```
248Use `backticks` to markup inline code within a paragraph.
249```
250
251### Code (blocks)
252
253Create a fenced code block using three backticks before and after a
254block of code, preceeded and followed by blank lines:
255
256```
257 This is a simple hello world program in C:
258
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700259 ```c
Shawn Pearcea5dad192015-02-20 16:46:35 -0800260 #include <stdio.h>
Andrew Bonventre4434b802015-09-29 12:27:56 -0400261
Shawn Pearcea5dad192015-02-20 16:46:35 -0800262 int main() {
263 printf("Hello, World.\n");
264 return 0;
265 }
266 ```
267
268 To compile it use `gcc hello.c`.
269```
270
271Text within a fenced code block is taken verbatim and is not
272processed for Markdown markup.
273
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700274Syntax highlighting can optionally be enabled for common languages
275by adding the language name in lowercase on the opening line.
276Supported languages include:
277
278|||---||| 2,2,2,2,4
279
280#### Scripting
281* bash, sh
282* lua
283* perl
284* python, py
285* ruby
286* tcl
287
Andrew Bonventre4434b802015-09-29 12:27:56 -0400288#### Web
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700289* css
290* dart
291* html
292* javascript, js
293* json
294
295#### Compiled
296* basic, vb
297* c
298* cpp (C++)
299* go
300* java
301* pascal
302* scala
303
304#### Markup
305* tex, latex
306* wiki
307* xml
308* xquery
309* xsl
310* yaml
311
312#### Other
313* clj (Clojure)
314* erlang
315* hs (Haskell)
316* lisp
317* [llvm](http://llvm.org/docs/LangRef.html)
318* matlab
319* ml (OCaml, SML, F#)
320* r
321* [rd](http://cran.r-project.org/doc/manuals/R-exts.html)
322* rust
323* sql
324* vhdl
325|||---|||
326
Shawn Pearcea5dad192015-02-20 16:46:35 -0800327### Horizontal rules
328
329A horizontal rule can be inserted using GitHub style `--` surrounded
330by blank lines. Alternatively repeating `-` or `*` and space on a
331line will also create a horizontal rule:
332
333```
334--
335
336- - - -
337
338* * * *
339```
340
341### Links
342
343Wrap text in `[brackets]` and the link destination in parens
344`(http://...)` such as:
345
346```
347Visit [this site](http://example.com/) for more examples.
348```
349
350Links can also use references to obtain URLs from elsewhere in the
351same document. This style can be useful if the same URL needs to be
352mentioned multiple times, is too long to cleanly place within text,
353or the link is within a table cell:
354
355```
356Search for [markdown style][1] examples.
357
358[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
359```
360
361References can be simplified if the text alone is sufficient:
362
363```
364Visit [Google] to search the web.
365
366[Google]: https://www.google.com/
367```
368
369Automatic hyperlinking can be used where the link text should
370obviously also be the URL:
371
372```
373Use https://www.google.com/ to search the web.
374```
375
376Well formed URLs beginning with `https://`, `http://`, and `mailto:`
377are used as written for the link's destination. Malformed URLs may be
378replaced with `#zSoyz` to prevent browser evaluation of dangerous
379content.
380
381HTML escaping of URL characters such as `&` is handled internally by
382the parser/formatter. Documentation writers should insert the URL
383literally and allow the parser and formatter to make it HTML safe.
384
385Relative links such as `../src/api.md` are resolved relative to the
386current markdown's file path within the Git repository. Absolute
387links such as `/src/api.md` are resolved relative to the top of the
388enclosing Git repository, but within the same branch or Git commit.
389Links may point to any file in the repository. A link to a `*.md`
390file will present the rendered markdown, while a link to a source file
391will display the syntax highlighted source.
392
Shawn Pearce25d91962015-06-22 15:35:36 -0700393### Named anchors
394
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700395Explicit anchors can be inserted anywhere in the document using
396`<a name="tag"></a>` or `{#tag}`.
397
398Implicit anchors are automatically created for each
399[heading](#Headings). For example `## Section 1` will have
400the anchor `Section-1`.
401
402*** note
403*Anchor generation*
404
405* letters and digits, after removing accents (á → a)
David Pursehousef7680782015-06-24 02:52:12 +0000406* spaces are replaced with hyphens (`-`)
407* other characters are replaced with underscores (`_`)
408* runs of hyphens and underscores are collapsed
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700409***
410
411If a document contains the same named subsection under different
412parents the parent anchor will prefix the subsections to
413disambiguate. For example the following document will have anchors
414`Running-Format` and `Coding-Format` and `Libraries` as that subsection
415is unique:
416
417```
418## Running
419### Format
420## Coding
421### Format
422### Libraries
423```
424
425When placed in a section header the explicit anchor will override
426the automatic anchor. The following are identical and associate
427the anchor `live-examples` with the section header instead of the
428automaticly generated name `Examples`.
Shawn Pearce25d91962015-06-22 15:35:36 -0700429
430```
431## Examples {#live-examples}
432## Examples <a name="live-examples"></a>
433```
434
Shawn Pearcea5dad192015-02-20 16:46:35 -0800435### Images
436
437Similar to links but begin with `!` to denote an image reference:
438
439```
440![diffy the kung fu review cuckoo](http://commondatastorage.googleapis.com/gerrit-static/diffy-w200.png)
441```
442
443For images the text in brackets will be included as the alt text for
444screen readers.
445
446Well formed image URLs beginning with `https://` and `http://` will be
447used as written for the `<img src="...">` attribute. Malformed URLs
448will be replaced with a broken `data:` reference to prevent browsers
449from trying to load a bad destination.
450
451Relative and absolute links to image files within the Git repository
452(such as `../images/banner.png`) are resolved during rendering by
453inserting the base64 encoding of the image using a `data:` URI. Only
454PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`) and GIF (`*.gif`) image
455formats are supported when referenced from the Git repository.
456
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700457Unsupported extensions or files larger than [image size](#Image-size)
458limit (default 256K) will display a broken image.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800459
460*** note
461_Inline image caching_
462
463Gitiles allows browsers to locally cache rendered markdown pages.
464Cache invalidation is triggered by the markdown file being modified
465and having a different SHA-1 in Git. Inlined images may need a
466documentation file update to be refreshed when viewed through unstable
467URLs like `/docs/+/master/index.md`.
468***
469
470### HTML
471
472HTML tags are not supported. HTML will be dropped on the floor by the
473parser with no warnings, and no output from that section of the
474document.
475
Shawn Pearce25d91962015-06-22 15:35:36 -0700476There is a small exception for `<a name>` and `<iframe>` elements, see
477[named anchor](#Named-anchors) and [HTML IFrame](#HTML-IFrame).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800478
479## Markdown extensions
480
481Gitiles includes additional extensions to the Markdown language that
482make documentation writing for the web easier without using raw HTML.
483
484### Table of contents
485
486Place `[TOC]` surrounded by blank lines to insert a generated
487table of contents extracted from the H1, H2, and H3 headers
488used within the document:
489
490```
491# Title
492
493[TOC]
494
495## Section 1
496Blah blah...
497
498## Section 2
499Go on...
500```
501
502H1 headers are omitted from the table of contents if there is only one
503level one header present. This allows H1 to be used as the document
504title without creating an unnecessary entry in the table of contents.
505
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700506Anchors are automatically extracted from the headers, see
507[named anchors](#Named-anchors).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800508
509### Notification, aside, promotion blocks
510
511Similar to fenced code blocks these blocks start and end with `***`,
512are surrounded by blank lines, and include the type of block on the
513opening line.
514
515#### Note
516
517```
518*** note
519**Warning:** watch out for nested formatting.
520***
521```
522
523*** note
524**Warning:** watch out for nested formatting.
525***
526
527#### Aside
528
529```
530*** aside
531An aside can stand off less interesting text.
532***
533```
534
535*** aside
536An aside can stand off less interesting text.
537***
538
539#### Promo
540
541```
542*** promo
543Promotions can raise awareness of an important concept.
544***
545```
546
547*** promo
548Promotions can raise awareness of an important concept.
549***
550
551### Column layout
552
Shawn Pearceecddc612015-02-20 22:09:47 -0800553Gitiles markdown includes support for up to 12 columns of text across
554the width of the page. By default space is divided equally between
555the columns.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800556
557|||---|||
558#### Columns
559
560can save space.
561
562#### Prettify
563
564the page layout.
565
566*** promo
567#### Can be
568
569trendy.
570***
571|||---|||
572
573A column layout is denoted by a block starting and ending with the
574sequence `|||---|||`. Within the layout a new column is started for
575each header or note/promo/aside block and all text and formatting flow
576into that column until a new column is started.
577
578```
579|||---|||
580#### Columns
581
582can save space.
583
584#### Prettify
585
586the page layout.
587
588*** promo
589#### Can be
590
591trendy.
592***
593|||---|||
594```
595
Shawn Pearceecddc612015-02-20 22:09:47 -0800596Column spans can be specified on the first line as a comma separated
597list. In the example below the first column is 4 wide or 4/12ths of
598the page width, the second is 2 wide (or 2/12ths) and the final column
599is 6 wide (6/12ths or 50%) of the page.
600
601```
602|||---||| 4,2,6
603```
604
605An empty column can be inserted by prefixing its width with `:`,
606for example shifting content onto the right by padding 6 columns
607on the left:
608
609```
610|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700611#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800612|||---|||
613```
614
615renders as:
616
617|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700618#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800619|||---|||
620
Shawn Pearcea5dad192015-02-20 16:46:35 -0800621### HTML IFrame
622
623Although HTML is stripped the parser has special support for a limited
624subset of `<iframe>` elements:
625
626```
627<iframe src="https://example.com/embed" height="200px" width="400px"></iframe>
628```
629
630The parser allows whitespace including newlines between attributes,
631but strictly limits the supported attribute set to:
632
633src
634: An `https://` or `http://` URL of the page to embed inside of an
635iframe at this position in the document. Malformed URLs will cause
636the iframe to be silently dropped. _(required)_
637
638height
639: CSS pixel height such as `250px` defining the amount of vertical
640space to give to the embedded content. Only `px` units are supported;
641a malformed dimension will drop the iframe. _(required)_
642
643width
644: CSS pixel width such as `250px` or a precentage such as `80%`
645defining the amount of horizontal space to give to the embedded
646content. Only `px` units or `%` are supported; a malformed dimension
647will drop the iframe. _(required)_
648
649frameborder
650: By default a border is drawn around the iframe by the browser. The
651border can be hidden by adding `frameborder="0"` to the iframe tag.
652_(optional)_
653
654Embedded source URLs must also be whitelisted by the Gitiles
655`markdown.allowiframe` configuration variable.
656
657## Site layout
658
659Gitiles includes additional support to create functional documentation
660sites served directly from Git repositories.
661
662### Navigation bar
663
664A top level navigation bar is automatically included on all pages if
665there is a `navbar.md` file present in the top of the repository.
666This file should be a simple bulleted list of links to include in the
667navigation bar.
668
669```
670* [Home](/index.md)
671* [Markdown](/docs/markdown.md)
672* [Configuration](/docs/configuration.md)
673```
674
675Links are resolved relative to the current page, not `navbar.md`.
676Links to other files within the repository should use absolute paths
677to ensure they are resolved correctly from any Markdown file within
678the repository.
679
680### Site title
681
Mike Colagrossoad028212016-01-20 23:25:59 -0700682A site-wide banner is displayed on all Markdown pages if `navbar.md`
683includes an H1 header. The text of the header is displayed on the
684left side of the banner.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800685
686```
687# Gitiles
688
689* [Home](/index.md)
690```
691
692### Site logo
693
694An optional logo image is displayed in the banner to the left of the
695site title if a `[logo]` reference exists in `navbar.md`. This image
696should be no taller than 45 px.
697
698```
699# Gitiles
700
701[logo]: /images/site_logo.png
702```
703
704See [images](#Images) above for acceptable URLs and how repository
705relative paths are handled by inline data URIs.
706
707### Home link
708
709Both the site logo (if present) and site title are wrapped in a link
710if the `[home]` reference is declared in `navbar.md`. This is
711typically also used in the outline for the navigation bar:
712
713```
714# Gitiles
715
716* [Home][home]
717* [Markdown](/docs/markdown.md)
718
719[home]: /index.md
720```
721
722### Page title
723
724Titles for pages are extracted from the first H1 heading appearing in
725the document. This is traditionally placed on the first line of the
726markdown file, e.g.:
727
728```
729# Markdown
730```
731
732The title is included in the HTML `<title>` element and also in the
733right side of the banner if `navbar.md` defines a
734[site title](#Site-title).
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700735
736## Configuration
737
738The `gitiles.config` file supporting the site contains several
739configuration options that impact markdown rendering.
740
741### Disabling markdown
742
743Markdown can be completely disabled by setting render to false.
744
745```
746[markdown]
747 render = false
748```
749
750### Markdown size
751
752Markdown files are limited by default to 5 MiB of input text
753per file. This limit is configurable, but should not be raised
754beyond available memory.
755
756```
757[markdown]
758 inputLimit = 5M
759```
760
761### Image size
762
763Referenced [images are inlined](#Images) as base64 encoded URIs.
764The image limit places an upper bound on the byte size of input.
765
766```
767[markdown]
768 imageLimit = 256K
769```
770
Shawn Pearce0e5fc542016-02-15 14:27:05 -0800771### Parsing timeout
772
773Parsing Markdown can be expensive so this implementation places
774a default upper bound of 2 seconds on running time per document.
775This is measured in wall clock time from the start of the request.
776
777```
778[markdown]
779 parseTimeout = 2s
780```
781
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700782### Google Analytics
783
784[Google Analytics](https://www.google.com/analytics/) can be
785enabled on every rendered markdown page by adding the Property ID
786to the configuration file:
787
788```
789[google]
790 analyticsId = UA-XXXX-Y
791```