# Markdown
The [Gitiles](https://gerrit.googlesource.com/gitiles/) source browser
automatically renders `*.md` Markdown files into HTML for simplified
documentation.
[TOC]
## Access controls
Access controls for documentation is identical to source code.
Documentation stored with source files shares the same permissions.
Documentation stored in a separate Git repository can use different
access controls. If Gerrit Code Review is being used, branch level
read permissions can be used to grant or restrict access to any
documentation branches.
## READMEs
Files named `README.md` are automatically displayed below the file's
directory listing. For the top level directory this mirrors the
standard [GitHub](https://github.com/) presentation.
*** promo
README.md files are meant to provide orientation for developers
browsing the repository, especially first-time users.
***
We recommend that Git repositories have an up-to-date top-level
`README.md` file.
## Markdown syntax
Gitiles supports the core Markdown syntax described in
[Markdown Basics]. Additional extensions are supported
to more closely match [GitHub Flavored Markdown] and
simplify documentation writing.
[Markdown Basics]: http://daringfireball.net/projects/markdown/basics
[GitHub Flavored Markdown]: https://help.github.com/articles/github-flavored-markdown/
### Paragraphs
Paragraphs are one or more lines of consecutive text, followed by
one or more blank lines. Line breaks within a paragraph are ignored
by the parser, allowing authors to line-wrap text at any comfortable
column width.
```
Documentation writing can be fun and profitable
by helping users to learn and solve problems.
After documentation is written, it needs to be published on the
web where it can be easily accessed for reading.
```
### Headings
Headings can be indicated by starting the line with one or more `#`
marks. The number of `#` used determines the depth of the heading in
the document outline. Headings 1 through 6 (`######`) are supported.
```
# A level one (H1) heading
## A level two (H2) heading
### A level three (H3) heading
```
Headings can also use the less popular two line `======` and `------`
forms to create H1 and H2 level headers:
```
A first level header
====================
A second level header
---------------------
```
This form is discouraged as maintaining the length of the `===` or
`---` lines to match the preceding line can be tedious work that is
unnecessary with the `#` headers.
### Lists
A bullet list:
```
* Fruit
* Orange
* Pear
* Cake
```
will render into HTML as:
* Fruit
* Orange
* Pear
* Cake
The second level items (above Orange, Pear) must be indented with more
spaces than the item they are nested under. Above 2 spaces were used.
Additionally, the entire list must be preceded and followed by a blank
line.
A numbered list:
```
1. Fruit
1. Orange
2. Pear
5. Cake
```
will render into HTML as:
1. Fruit
1. Orange
2. Pear
5. Cake
List items will be renumbered sequentially by the browser, which is
why `5` above displays as `2`. Even with this feature it is a good
idea to maintain list item numbers in the source Markdown to simplify
reading the source file.
Like bullet lists, numbered lists can be nested by using more leading
space than the prior list item.
Paragraphs can be properly nested within lists by indenting with at
least 2 leading spaces:
```
1. Fruit
In botany, a fruit is the seed-bearing structure in flowering
plants.
In common language usage, "fruit" normally means the fleshy
seed-associated structures of a plant that are sweet or sour, and
edible in the raw state, such as apples, bananas, grapes, lemons,
oranges, and strawberries.
2. Cake
The cake is a lie.
```
### Tables
Requires `markdown.tables` to be true (default).
Simple tables are supported with column alignment. The first line is
the header row and subsequent lines are data rows:
```
| Food | Calories | Tasty? |
|-------|---------:|:------:|
| Apple | 95 | Yes |
| Pear | 102 | Yes |
| Hay | 977 | |
```
will render as:
| Food | Calories | Tasty? |
|-------|---------:|:------:|
| Apple | 95 | Yes |
| Pear | 102 | Yes |
| Hay | 977 | |
Placing `:` in the separator line indicates how the column should be
aligned. A colon on the left side is a **left-aligned** column; a
colon on the right-most side is **right-aligned**; a colon on both
sides is **center-aligned**. If no alignment is specified, the column
is aligned with the default for HTML `
` tags (left-aligned by
default unless overridden by css).
Empty table cells are indicated by whitespace between the column
dividers (`| |`) while multiple column cells omit the whitespace.
### Emphasis
Emphasize paragraph text with *italic* and **bold** styles. Either `_`
or `*` can be used for italic (1 character) and bold text (2
characters). This allows styles to be mixed within a statement:
```
Emphasize paragraph text with *italic* and **bold** text.
**It is _strongly_ encouraged to review documentation for typos.**
```
**It is _strongly_ encouraged to review documentation for typos.**
Emphasis within_words_is_ignored which helps write technical
documentation. Literal \*bold* can be forced by prefixing the
opening `*` with \ such as `\*bold*`.
### Strikethrough
Requires `markdown.strikethrough` to be true (default).
Text can be ~~struck out~~ within a paragraph:
```
Text can be ~~struck out~~ within a paragraph.
```
Note two tildes are required (`~~`) on either side of the struck out
section of text.
### Blockquotes
Blockquoted text can be used to stand off text obtained from
another source:
```
Sir Winston Churchill once said:
> A lie gets halfway around the world before the truth has a
> chance to get its pants on.
```
renders as:
Sir Winston Churchill once said:
> A lie gets halfway around the world before the truth has a
> chance to get its pants on.
### Code (inline)
Use `backticks` to markup inline code within a paragraph:
```
Use `backticks` to markup inline code within a paragraph.
```
### Code (blocks)
Create a fenced code block using three backticks before and after a
block of code, preceeded and followed by blank lines:
````
This is a simple hello world program in C:
``` c
#include
int main() {
printf("Hello, World.\n");
return 0;
}
```
To compile it use `gcc hello.c`.
````
Text within a fenced code block is taken verbatim and is not
processed for Markdown markup.
Syntax highlighting can optionally be enabled for common languages
by adding the language name in lowercase on the opening line.
Supported languages include:
|||---||| 2,2,2,2,4
#### Scripting
* bash, sh
* lua
* perl
* python, py
* ruby
* tcl
#### Web
* css
* dart
* html
* javascript, js
* json
#### Compiled
* basic, vb
* c
* cpp (C++)
* go
* java
* pascal
* scala
#### Markup
* tex, latex
* wiki
* xml
* xquery
* xsl
* yaml
#### Other
* clj (Clojure)
* erlang
* hs (Haskell)
* lisp
* [llvm](http://llvm.org/docs/LangRef.html)
* matlab
* ml (OCaml, SML, F#)
* r
* [rd](http://cran.r-project.org/doc/manuals/R-exts.html)
* rust
* sql
* vhdl
|||---|||
### Horizontal rules
If `markdown.ghthematicbreak` is true, a horizontal rule can be
inserted using GitHub style `--` surrounded by blank lines.
Alternatively repeating `-` or `*` and space on a line will also
create a horizontal rule:
```
---
- - - -
* * * *
```
### Links
Wrap text in `[brackets]` and the link destination in parens
`(http://...)` such as:
```
Visit [this site](http://example.com/) for more examples.
```
Links can also use references to obtain URLs from elsewhere in the
same document. This style can be useful if the same URL needs to be
mentioned multiple times, is too long to cleanly place within text,
or the link is within a table cell:
```
Search for [markdown style][1] examples.
[1]: https://www.google.com/?gws_rd=ssl#q=markdown+style+guide
```
References can be simplified if the text alone is sufficient:
```
Visit [Google] to search the web.
[Google]: https://www.google.com/
```
Automatic hyperlinking can be used where the link text should
obviously also be the URL:
```
Use https://www.google.com/ to search the web.
```
Well formed URLs beginning with `https://`, `http://`, and `mailto:`
are used as written for the link's destination. Malformed URLs may be
replaced with `about:invalid#zSoyz` to prevent browser evaluation of dangerous
content.
HTML escaping of URL characters such as `&` is handled internally by
the parser/formatter. Documentation writers should insert the URL
literally and allow the parser and formatter to make it HTML safe.
Relative links such as `../src/api.md` are resolved relative to the
current markdown's file path within the Git repository. Absolute
links such as `/src/api.md` are resolved relative to the top of the
enclosing Git repository, but within the same branch or Git commit.
Links may point to any file in the repository. A link to a `*.md`
file will present the rendered markdown, while a link to a source file
will display the syntax highlighted source.
### Named anchors
Explicit anchors can be inserted anywhere in the document using
``, or `{#tag}` if `markdown.namedanchor` is true.
Implicit anchors are automatically created for each
[heading](#Headings). For example `## Section 1` will have
the anchor `Section-1`.
*** note
*Anchor generation*
* letters and digits, after removing accents (á → a)
* spaces are replaced with hyphens (`-`)
* other characters are replaced with underscores (`_`)
* runs of hyphens and underscores are collapsed
***
If a document contains the same named subsection under different
parents the parent anchor will prefix the subsections to
disambiguate. For example the following document will have anchors
`Running-Format` and `Coding-Format` and `Libraries` as that subsection
is unique:
```
## Running
### Format
## Coding
### Format
### Libraries
```
When placed in a section header the explicit anchor will override
the automatic anchor. The following are identical and associate
the anchor `live-examples` with the section header instead of the
automaticly generated name `Examples`.
```
## Examples {#live-examples}
## Examples
```
### Images
Similar to links but begin with `!` to denote an image reference:
```

```
For images the text in brackets will be included as the alt text for
screen readers.
Well formed image URLs beginning with `https://` and `http://` will be
used as written for the ` ` attribute. Malformed URLs
will be replaced with a broken `data:` reference to prevent browsers
from trying to load a bad destination.
Relative and absolute links to image files within the Git repository
(such as `../images/banner.png`) are resolved during rendering by
inserting the base64 encoding of the image using a `data:` URI. Only
PNG (`*.png`), JPEG (`*.jpg` or `*.jpeg`) and GIF (`*.gif`) image
formats are supported when referenced from the Git repository.
Unsupported extensions or files larger than [image size](#Image-size)
limit (default 256K) will display a broken image.
*** note
_Inline image caching_
Gitiles allows browsers to locally cache rendered markdown pages.
Cache invalidation is triggered by the markdown file being modified
and having a different SHA-1 in Git. Inlined images may need a
documentation file update to be refreshed when viewed through unstable
URLs like `/docs/+/master/index.md`.
***
### HTML
Most HTML tags are not supported. HTML will be dropped on the floor
by the parser with no warnings, and no output from that section of the
document.
If `markdown.safehtml` is true there are small exceptions for ` `,
` `, `` and ` |