blob: fdc303196934aba8bd55ade726c7b61052669d02 [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
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700257 ```c
Shawn Pearcea5dad192015-02-20 16:46:35 -0800258 #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
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700272Syntax highlighting can optionally be enabled for common languages
273by adding the language name in lowercase on the opening line.
274Supported languages include:
275
276|||---||| 2,2,2,2,4
277
278#### Scripting
279* bash, sh
280* lua
281* perl
282* python, py
283* ruby
284* tcl
285
286### Web
287* css
288* dart
289* html
290* javascript, js
291* json
292
293#### Compiled
294* basic, vb
295* c
296* cpp (C++)
297* go
298* java
299* pascal
300* scala
301
302#### Markup
303* tex, latex
304* wiki
305* xml
306* xquery
307* xsl
308* yaml
309
310#### Other
311* clj (Clojure)
312* erlang
313* hs (Haskell)
314* lisp
315* [llvm](http://llvm.org/docs/LangRef.html)
316* matlab
317* ml (OCaml, SML, F#)
318* r
319* [rd](http://cran.r-project.org/doc/manuals/R-exts.html)
320* rust
321* sql
322* vhdl
323|||---|||
324
Shawn Pearcea5dad192015-02-20 16:46:35 -0800325### Horizontal rules
326
327A horizontal rule can be inserted using GitHub style `--` surrounded
328by blank lines. Alternatively repeating `-` or `*` and space on a
329line will also create a horizontal rule:
330
331```
332--
333
334- - - -
335
336* * * *
337```
338
339### Links
340
341Wrap text in `[brackets]` and the link destination in parens
342`(http://...)` such as:
343
344```
345Visit [this site](http://example.com/) for more examples.
346```
347
348Links can also use references to obtain URLs from elsewhere in the
349same document. This style can be useful if the same URL needs to be
350mentioned multiple times, is too long to cleanly place within text,
351or the link is within a table cell:
352
353```
354Search for [markdown style][1] examples.
355
356[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
357```
358
359References can be simplified if the text alone is sufficient:
360
361```
362Visit [Google] to search the web.
363
364[Google]: https://www.google.com/
365```
366
367Automatic hyperlinking can be used where the link text should
368obviously also be the URL:
369
370```
371Use https://www.google.com/ to search the web.
372```
373
374Well formed URLs beginning with `https://`, `http://`, and `mailto:`
375are used as written for the link's destination. Malformed URLs may be
376replaced with `#zSoyz` to prevent browser evaluation of dangerous
377content.
378
379HTML escaping of URL characters such as `&` is handled internally by
380the parser/formatter. Documentation writers should insert the URL
381literally and allow the parser and formatter to make it HTML safe.
382
383Relative links such as `../src/api.md` are resolved relative to the
384current markdown's file path within the Git repository. Absolute
385links such as `/src/api.md` are resolved relative to the top of the
386enclosing Git repository, but within the same branch or Git commit.
387Links may point to any file in the repository. A link to a `*.md`
388file will present the rendered markdown, while a link to a source file
389will display the syntax highlighted source.
390
Shawn Pearce25d91962015-06-22 15:35:36 -0700391### Named anchors
392
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700393Explicit anchors can be inserted anywhere in the document using
394`<a name="tag"></a>` or `{#tag}`.
395
396Implicit anchors are automatically created for each
397[heading](#Headings). For example `## Section 1` will have
398the anchor `Section-1`.
399
400*** note
401*Anchor generation*
402
403* letters and digits, after removing accents (á → a)
404* spaces are replaced with -
405* other characters are replaced with _
406* runs of - and _ are collapsed
407***
408
409If a document contains the same named subsection under different
410parents the parent anchor will prefix the subsections to
411disambiguate. For example the following document will have anchors
412`Running-Format` and `Coding-Format` and `Libraries` as that subsection
413is unique:
414
415```
416## Running
417### Format
418## Coding
419### Format
420### Libraries
421```
422
423When placed in a section header the explicit anchor will override
424the automatic anchor. The following are identical and associate
425the anchor `live-examples` with the section header instead of the
426automaticly generated name `Examples`.
Shawn Pearce25d91962015-06-22 15:35:36 -0700427
428```
429## Examples {#live-examples}
430## Examples <a name="live-examples"></a>
431```
432
Shawn Pearcea5dad192015-02-20 16:46:35 -0800433### Images
434
435Similar to links but begin with `!` to denote an image reference:
436
437```
438![diffy the kung fu review cuckoo](http://commondatastorage.googleapis.com/gerrit-static/diffy-w200.png)
439```
440
441For images the text in brackets will be included as the alt text for
442screen readers.
443
444Well formed image URLs beginning with `https://` and `http://` will be
445used as written for the `<img src="...">` attribute. Malformed URLs
446will be replaced with a broken `data:` reference to prevent browsers
447from trying to load a bad destination.
448
449Relative and absolute links to image files within the Git repository
450(such as `../images/banner.png`) are resolved during rendering by
451inserting the base64 encoding of the image using a `data:` URI. Only
452PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`) and GIF (`*.gif`) image
453formats are supported when referenced from the Git repository.
454
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700455Unsupported extensions or files larger than [image size](#Image-size)
456limit (default 256K) will display a broken image.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800457
458*** note
459_Inline image caching_
460
461Gitiles allows browsers to locally cache rendered markdown pages.
462Cache invalidation is triggered by the markdown file being modified
463and having a different SHA-1 in Git. Inlined images may need a
464documentation file update to be refreshed when viewed through unstable
465URLs like `/docs/+/master/index.md`.
466***
467
468### HTML
469
470HTML tags are not supported. HTML will be dropped on the floor by the
471parser with no warnings, and no output from that section of the
472document.
473
Shawn Pearce25d91962015-06-22 15:35:36 -0700474There is a small exception for `<a name>` and `<iframe>` elements, see
475[named anchor](#Named-anchors) and [HTML IFrame](#HTML-IFrame).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800476
477## Markdown extensions
478
479Gitiles includes additional extensions to the Markdown language that
480make documentation writing for the web easier without using raw HTML.
481
482### Table of contents
483
484Place `[TOC]` surrounded by blank lines to insert a generated
485table of contents extracted from the H1, H2, and H3 headers
486used within the document:
487
488```
489# Title
490
491[TOC]
492
493## Section 1
494Blah blah...
495
496## Section 2
497Go on...
498```
499
500H1 headers are omitted from the table of contents if there is only one
501level one header present. This allows H1 to be used as the document
502title without creating an unnecessary entry in the table of contents.
503
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700504Anchors are automatically extracted from the headers, see
505[named anchors](#Named-anchors).
Shawn Pearcea5dad192015-02-20 16:46:35 -0800506
507### Notification, aside, promotion blocks
508
509Similar to fenced code blocks these blocks start and end with `***`,
510are surrounded by blank lines, and include the type of block on the
511opening line.
512
513#### Note
514
515```
516*** note
517**Warning:** watch out for nested formatting.
518***
519```
520
521*** note
522**Warning:** watch out for nested formatting.
523***
524
525#### Aside
526
527```
528*** aside
529An aside can stand off less interesting text.
530***
531```
532
533*** aside
534An aside can stand off less interesting text.
535***
536
537#### Promo
538
539```
540*** promo
541Promotions can raise awareness of an important concept.
542***
543```
544
545*** promo
546Promotions can raise awareness of an important concept.
547***
548
549### Column layout
550
Shawn Pearceecddc612015-02-20 22:09:47 -0800551Gitiles markdown includes support for up to 12 columns of text across
552the width of the page. By default space is divided equally between
553the columns.
Shawn Pearcea5dad192015-02-20 16:46:35 -0800554
555|||---|||
556#### Columns
557
558can save space.
559
560#### Prettify
561
562the page layout.
563
564*** promo
565#### Can be
566
567trendy.
568***
569|||---|||
570
571A column layout is denoted by a block starting and ending with the
572sequence `|||---|||`. Within the layout a new column is started for
573each header or note/promo/aside block and all text and formatting flow
574into that column until a new column is started.
575
576```
577|||---|||
578#### Columns
579
580can save space.
581
582#### Prettify
583
584the page layout.
585
586*** promo
587#### Can be
588
589trendy.
590***
591|||---|||
592```
593
Shawn Pearceecddc612015-02-20 22:09:47 -0800594Column spans can be specified on the first line as a comma separated
595list. In the example below the first column is 4 wide or 4/12ths of
596the page width, the second is 2 wide (or 2/12ths) and the final column
597is 6 wide (6/12ths or 50%) of the page.
598
599```
600|||---||| 4,2,6
601```
602
603An empty column can be inserted by prefixing its width with `:`,
604for example shifting content onto the right by padding 6 columns
605on the left:
606
607```
608|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700609#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800610|||---|||
611```
612
613renders as:
614
615|||---||| :6,3
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700616#### Right
Shawn Pearceecddc612015-02-20 22:09:47 -0800617|||---|||
618
Shawn Pearcea5dad192015-02-20 16:46:35 -0800619### HTML IFrame
620
621Although HTML is stripped the parser has special support for a limited
622subset of `<iframe>` elements:
623
624```
625<iframe src="https://example.com/embed" height="200px" width="400px"></iframe>
626```
627
628The parser allows whitespace including newlines between attributes,
629but strictly limits the supported attribute set to:
630
631src
632: An `https://` or `http://` URL of the page to embed inside of an
633iframe at this position in the document. Malformed URLs will cause
634the iframe to be silently dropped. _(required)_
635
636height
637: CSS pixel height such as `250px` defining the amount of vertical
638space to give to the embedded content. Only `px` units are supported;
639a malformed dimension will drop the iframe. _(required)_
640
641width
642: CSS pixel width such as `250px` or a precentage such as `80%`
643defining the amount of horizontal space to give to the embedded
644content. Only `px` units or `%` are supported; a malformed dimension
645will drop the iframe. _(required)_
646
647frameborder
648: By default a border is drawn around the iframe by the browser. The
649border can be hidden by adding `frameborder="0"` to the iframe tag.
650_(optional)_
651
652Embedded source URLs must also be whitelisted by the Gitiles
653`markdown.allowiframe` configuration variable.
654
655## Site layout
656
657Gitiles includes additional support to create functional documentation
658sites served directly from Git repositories.
659
660### Navigation bar
661
662A top level navigation bar is automatically included on all pages if
663there is a `navbar.md` file present in the top of the repository.
664This file should be a simple bulleted list of links to include in the
665navigation bar.
666
667```
668* [Home](/index.md)
669* [Markdown](/docs/markdown.md)
670* [Configuration](/docs/configuration.md)
671```
672
673Links are resolved relative to the current page, not `navbar.md`.
674Links to other files within the repository should use absolute paths
675to ensure they are resolved correctly from any Markdown file within
676the repository.
677
678### Site title
679
680A site wide banner is displayed on all Markdown pages if `navbar.md`
681includes a H1 header. The text of the header is display on the left
682side of the banner.
683
684```
685# Gitiles
686
687* [Home](/index.md)
688```
689
690### Site logo
691
692An optional logo image is displayed in the banner to the left of the
693site title if a `[logo]` reference exists in `navbar.md`. This image
694should be no taller than 45 px.
695
696```
697# Gitiles
698
699[logo]: /images/site_logo.png
700```
701
702See [images](#Images) above for acceptable URLs and how repository
703relative paths are handled by inline data URIs.
704
705### Home link
706
707Both the site logo (if present) and site title are wrapped in a link
708if the `[home]` reference is declared in `navbar.md`. This is
709typically also used in the outline for the navigation bar:
710
711```
712# Gitiles
713
714* [Home][home]
715* [Markdown](/docs/markdown.md)
716
717[home]: /index.md
718```
719
720### Page title
721
722Titles for pages are extracted from the first H1 heading appearing in
723the document. This is traditionally placed on the first line of the
724markdown file, e.g.:
725
726```
727# Markdown
728```
729
730The title is included in the HTML `<title>` element and also in the
731right side of the banner if `navbar.md` defines a
732[site title](#Site-title).
Shawn Pearce7b4044c2015-06-23 16:36:18 -0700733
734## Configuration
735
736The `gitiles.config` file supporting the site contains several
737configuration options that impact markdown rendering.
738
739### Disabling markdown
740
741Markdown can be completely disabled by setting render to false.
742
743```
744[markdown]
745 render = false
746```
747
748### Markdown size
749
750Markdown files are limited by default to 5 MiB of input text
751per file. This limit is configurable, but should not be raised
752beyond available memory.
753
754```
755[markdown]
756 inputLimit = 5M
757```
758
759### Image size
760
761Referenced [images are inlined](#Images) as base64 encoded URIs.
762The image limit places an upper bound on the byte size of input.
763
764```
765[markdown]
766 imageLimit = 256K
767```
768
769### Google Analytics
770
771[Google Analytics](https://www.google.com/analytics/) can be
772enabled on every rendered markdown page by adding the Property ID
773to the configuration file:
774
775```
776[google]
777 analyticsId = UA-XXXX-Y
778```