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