A quick guide to GitHub markdown for my own purposes. I'll eventually get around to making a better cheat sheet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

374 lines
10 KiB

3 years ago
  1. # github-markdown
  2. Borrowed from [Joshua Pekera's excellent template](https://gist.github.com/joshuapekera/5730539/)
  3. This is intended as a quick reference and showcase. For more complete info, see [John Gruber's original spec](http://daringfireball.net/projects/markdown/) and the [Github-flavored Markdown info page](http://github.github.com/github-flavored-markdown/).
  4. This cheatsheet is specifically *Markdown Here's* version of Github-flavored Markdown. This differs slightly in styling and syntax from what Github uses, so what you see below might vary a little from what you get in a *Markdown Here* email, but it should be pretty close.
  5. You can play around with Markdown on our [live demo page](http://www.markdown-here.com/livedemo.html).
  6. ##### Table of Contents
  7. [Headers](#headers)
  8. [Emphasis](#emphasis)
  9. [Lists](#lists)
  10. [Links](#links)
  11. [Images](#images)
  12. [Code and Syntax Highlighting](#code)
  13. [Tables](#tables)
  14. [Blockquotes](#blockquotes)
  15. [Inline HTML](#html)
  16. [Horizontal Rule](#hr)
  17. [Line Breaks](#lines)
  18. [Youtube videos](#videos)
  19. <a name="headers"/>
  20. ## Headers
  21. ```no-highlight
  22. # H1
  23. ## H2
  24. ### H3
  25. #### H4
  26. ##### H5
  27. ###### H6
  28. Alternatively, for H1 and H2, an underline-ish style:
  29. Alt-H1
  30. ======
  31. Alt-H2
  32. ------
  33. ```
  34. # H1
  35. ## H2
  36. ### H3
  37. #### H4
  38. ##### H5
  39. ###### H6
  40. Alternatively, for H1 and H2, an underline-ish style:
  41. Alt-H1
  42. ======
  43. Alt-H2
  44. ------
  45. <a name="emphasis"/>
  46. ## Emphasis
  47. ```no-highlight
  48. Emphasis, aka italics, with *asterisks* or _underscores_.
  49. Strong emphasis, aka bold, with **asterisks** or __underscores__.
  50. Combined emphasis with **asterisks and _underscores_**.
  51. Strikethrough uses two tildes. ~~Scratch this.~~
  52. ```
  53. Emphasis, aka italics, with *asterisks* or _underscores_.
  54. Strong emphasis, aka bold, with **asterisks** or __underscores__.
  55. Combined emphasis with **asterisks and _underscores_**.
  56. Strikethrough uses two tildes. ~~Scratch this.~~
  57. <a name="lists"/>
  58. ## Lists
  59. ```no-highlight
  60. 1. First ordered list item
  61. 2. Another item
  62. * Unordered sub-list.
  63. 1. Actual numbers don't matter, just that it's a number
  64. 1. Ordered sub-list
  65. 4. And another item.
  66. Some text that should be aligned with the above item.
  67. * Unordered list can use asterisks
  68. - Or minuses
  69. + Or pluses
  70. ```
  71. 1. First ordered list item
  72. 2. Another item
  73. * Unordered sub-list.
  74. 1. Actual numbers don't matter, just that it's a number
  75. 1. Ordered sub-list
  76. 4. And another item.
  77. Some text that should be aligned with the above item.
  78. * Unordered list can use asterisks
  79. - Or minuses
  80. + Or pluses
  81. <a name="links"/>
  82. ## Links
  83. There are two ways to create links.
  84. ```no-highlight
  85. [I'm an inline-style link](https://www.google.com)
  86. [I'm a reference-style link][Arbitrary case-insensitive reference text]
  87. [You can use numbers for reference-style link definitions][1]
  88. Or leave it empty and use the [link text itself][]
  89. Some text to show that the reference links can follow later.
  90. [arbitrary case-insensitive reference text]: https://www.mozilla.org
  91. [1]: http://slashdot.org
  92. [link text itself]: http://www.reddit.com
  93. ```
  94. [I'm an inline-style link](https://www.google.com)
  95. [I'm a reference-style link][Arbitrary case-insensitive reference text]
  96. [You can use numbers for reference-style link definitions][1]
  97. Or leave it empty and use the [link text itself][]
  98. Some text to show that the reference links can follow later.
  99. [arbitrary case-insensitive reference text]: https://www.mozilla.org
  100. [1]: http://slashdot.org
  101. [link text itself]: http://www.reddit.com
  102. <a name="images"/>
  103. ## Images
  104. ```no-highlight
  105. Here's our logo (hover to see the title text):
  106. Inline-style:
  107. ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
  108. Reference-style:
  109. ![alt text][logo]
  110. [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
  111. ```
  112. Here's our logo (hover to see the title text):
  113. Inline-style:
  114. ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
  115. Reference-style:
  116. ![alt text][logo]
  117. [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
  118. <a name="code"/>
  119. ## Code and Syntax Highlighting
  120. Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and *Markdown Here* -- support syntax highlighting. *Markdown Here* supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).
  121. ```no-highlight
  122. Inline `code` has `back-ticks around` it.
  123. ```
  124. Inline `code` has `back-ticks around` it.
  125. Blocks of code are either fenced by lines with three back-ticks <code>```</code>, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.
  126. ```no-highlight
  127. ```javascript
  128. var s = "JavaScript syntax highlighting";
  129. alert(s);
  130. ```
  131. ```python
  132. s = "Python syntax highlighting"
  133. print s
  134. ```
  135. ```
  136. No language indicated, so no syntax highlighting.
  137. But let's throw in a <b>tag</b>.
  138. ```
  139. ```
  140. ```javascript
  141. var s = "JavaScript syntax highlighting";
  142. alert(s);
  143. ```
  144. ```python
  145. s = "Python syntax highlighting"
  146. print s
  147. ```
  148. ```
  149. No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
  150. But let's throw in a <b>tag</b>.
  151. ```
  152. (Github Wiki pages don't seem to support syntax highlighting, so the above won't be colourful (the strings are not red, for example). Try it out in a *Markdown Here* email or a Github Markdown README or Github Issue -- you can preview a new Issue without submitting it.)
  153. Again, to see what languages are available for highlighting, and how to write those language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).
  154. <a name="tables"/>
  155. ## Tables
  156. Tables aren't part of the core Markdown spec, but they are part of GFM and *Markdown Here* supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.
  157. ```no-highlight
  158. Colons can be used to align columns.
  159. | Tables | Are | Cool |
  160. | ------------- |:-------------:| -----:|
  161. | col 3 is | right-aligned | $1600 |
  162. | col 2 is | centered | $12 |
  163. | zebra stripes | are neat | $1 |
  164. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
  165. Markdown | Less | Pretty
  166. --- | --- | ---
  167. *Still* | `renders` | **nicely**
  168. 1 | 2 | 3
  169. ```
  170. Colons can be used to align columns.
  171. | Tables | Are | Cool |
  172. | ------------- |:-------------:| -----:|
  173. | col 3 is | right-aligned | $1600 |
  174. | col 2 is | centered | $12 |
  175. | zebra stripes | are neat | $1 |
  176. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
  177. Markdown | Less | Pretty
  178. --- | --- | ---
  179. *Still* | `renders` | **nicely**
  180. 1 | 2 | 3
  181. <a name="blockquotes"/>
  182. ## Blockquotes
  183. ```no-highlight
  184. > Blockquotes are very handy in email to emulate reply text.
  185. > This line is part of the same quote.
  186. Quote break.
  187. > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
  188. ```
  189. > Blockquotes are very handy in email to emulate reply text.
  190. > This line is part of the same quote.
  191. Quote break.
  192. > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
  193. <a name="html"/>
  194. ## Inline HTML
  195. You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
  196. ```no-highlight
  197. <dl>
  198. <dt>Definition list</dt>
  199. <dd>Is something people use sometimes.</dd>
  200. <dt>Markdown in HTML</dt>
  201. <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
  202. </dl>
  203. ```
  204. <dl>
  205. <dt>Definition list</dt>
  206. <dd>Is something people use sometimes.</dd>
  207. <dt>Markdown in HTML</dt>
  208. <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
  209. </dl>
  210. <a name="hr"/>
  211. ## Horizontal Rule
  212. ```
  213. Three or more...
  214. ---
  215. Hyphens
  216. ***
  217. Asterisks
  218. ___
  219. Underscores
  220. ```
  221. Three or more...
  222. ---
  223. Hyphens
  224. ***
  225. Asterisks
  226. ___
  227. Underscores
  228. <a name="lines"/>
  229. ## Line Breaks
  230. My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.
  231. Here are some things to try out:
  232. ```
  233. Here's a line for us to start with.
  234. This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
  235. This line is also a separate paragraph, but...
  236. This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
  237. ```
  238. Here's a line for us to start with.
  239. This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
  240. This line is also begins a separate paragraph, but...
  241. This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
  242. (Technical note: *Markdown Here* uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
  243. <a name="videos"/>
  244. ## Youtube videos
  245. They can't be added directly but you can add an image with a link to the video like this:
  246. ```no-highlight
  247. <a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
  248. " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
  249. alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>
  250. ```
  251. Or, in pure Markdown, but losing the image sizing and border:
  252. ```no-highlight
  253. [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
  254. ```