--- name: Markdown contributors: - ["Dan Turkel", "http://danturkel.com/"] - ["Jacob Ward", "http://github.com/JacobCWard/"] - ["Tomáš Hartman", "https://github.com/tomas-hartman"] filename: markdown.md --- Markdown was created by John Gruber in 2004. It's meant to be an easy to read and write syntax which converts easily to HTML (and now many other formats as well). Markdown also varies in implementation from one parser to a next. This guide will attempt to clarify when features are universal or when they are specific to a certain parser. ## HTML Elements Markdown is a superset of HTML, so any HTML file is valid Markdown. ```md ``` ## Headings You can create HTML elements `
` element) by indenting
a line with four spaces or a tab.
```md
This is code
So is this
```
You can also re-tab (or add an additional four spaces) for indentation
inside your code.
```md
my_array.each do |item|
puts item
end
```
Inline code can be created using the backtick character `` ` ``.
```md
John didn't even know what the `go_to()` function did!
```
In GitHub Flavored Markdown, you can use a special syntax for code.
````md
```ruby
def foobar
puts "Hello world!"
end
```
````
The above text doesn't require indenting, plus GitHub will use syntax
highlighting of the language you specify after the opening ```
.
## Horizontal rule
Horizontal rules (`
`) are easily added with three or more asterisks or
hyphens, with or without spaces.
```md
***
---
- - -
****************
```
## Links
One of the best things about markdown is how easy it is to make links. Put
the text to display in hard brackets [] followed by the url in parentheses ()
```md
[Click me!](http://test.com/)
```
You can also add a link title using quotes inside the parentheses.
```md
[Click me!](http://test.com/ "Link to Test.com")
```
Relative paths work too.
```md
[Go to music](/music/).
```
Markdown also supports reference style links.
```md
[Click this link][link1] for more info about it!
[Also check out this link][foobar] if you want to.
[link1]: http://test.com/ "Cool!"
[foobar]: http://foobar.biz/ "Alright!"
```
The title can also be in single quotes or in parentheses, or omitted
entirely. The references can be anywhere in your document and the reference IDs
can be anything so long as they are unique.
There is also "implicit naming" which lets you use the link text as the id.
```md
[This][] is a link.
[This]: http://thisisalink.com/
```
But it's not that commonly used.
### Table of contents
Some Markdown flavors even make use of the combination of lists, links and
headings in order to create tables of contents. In this case, heading titles in
lowercase are prepended with hash (`#`) and are used as link ids. Should the
heading have multiple words, they will be connected with a hyphen (`-`), that
also replaces some special characters. (Some other special characters are
omitted though.)
```md
- [Heading](#heading)
- [Another heading](#another-heading)
- [Chapter](#chapter)
- [Subchapter ](#subchapter-h3-)
```
Nonetheless, this is a feature that might not be working in all Markdown
implementations the same way.
## Images
Images are done the same way as links but with an exclamation point in front!
```md
![This is the alt-attribute for my image](http://imgur.com/myimage.jpg "An optional title")
```
And reference style works as expected.
```md
![This is the alt-attribute.][myimage]
[myimage]: relative/urls/cool/image.jpg "if you need a title, it's here"
```
## Miscellany
### Auto-links
```md
is equivalent to
[http://testwebsite.com/](http://testwebsite.com/)
```
### Auto-links for emails
```md
```
### Escaping characters
```md
I want to type *this text surrounded by asterisks* but I don't want it to be
in italics, so I do this: \*this text surrounded by asterisks\*.
```
### Keyboard keys
In GitHub Flavored Markdown, you can use a `` tag to represent keyboard
keys.
```md
Your computer crashed? Try sending a
Ctrl+Alt+Del
```
### Tables
Tables are only available in GitHub Flavored Markdown and are slightly
cumbersome, but if you really want it:
```md
| Col1 | Col2 | Col3 |
| :----------- | :------: | ------------: |
| Left-aligned | Centered | Right-aligned |
| blah | blah | blah |
```
or, for the same results
```md
Col 1 | Col2 | Col3
:-- | :-: | --:
Ugh this is so ugly | make it | stop
```
## Markdownlint
In order to simplify work with Markdown and to unify its coding style,
`Markdownlint` has been created. Available as a
[separate tool](https://github.com/markdownlint/markdownlint)
as well as a plugin for some IDEs, it can be used to ensure validity and
readability of Markdown.
---
## Further reading
For more info, check out John Gruber's official post of syntax [here](http://daringfireball.net/projects/markdown/syntax) and Adam Pritchard's great cheatsheet [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
If you want to learn more on some major Markdown flavors' features, see:
- [GitHub Flavored Markdown](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
- [GitLab Flavored Markdown](https://docs.gitlab.com/ee/user/markdown.html)