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.

373 lines
9.8 KiB

3 years ago
  1. # Gitea (and presumably GitHub) Markdown
  2. This cheatsheet is what works (and in a few cases, *doesn't* work) in Gitea. I'm presuming that this will also work on GitHub but I would need to post it there before I can confirm.
  3. ## Table of Contents
  4. [Headers](##headers)
  5. [Emphasis](#emphasis)
  6. [Lists](#lists)
  7. [Links](#links)
  8. [Images](#images)
  9. [Code and Syntax Highlighting](#code)
  10. [Tables](#tables)
  11. [Blockquotes](#blockquotes)
  12. [Inline HTML](#html)
  13. [Horizontal Rule](#hr)
  14. [Line Breaks](#lines)
  15. [Youtube videos](#videos)
  16. ## Headers
  17. ```no-highlight
  18. # H1
  19. ## H2
  20. ### H3
  21. #### H4
  22. ##### H5
  23. ###### H6
  24. Alternatively, for H1 and H2, an underline-ish style:
  25. Alt-H1
  26. ======
  27. Alt-H2
  28. ------
  29. ```
  30. # H1
  31. ## H2
  32. ### H3
  33. #### H4
  34. ##### H5
  35. ###### H6
  36. Alternatively, for H1 and H2, an underline-ish style:
  37. Alt-H1
  38. ======
  39. Alt-H2
  40. ------
  41. <a name="emphasis"/>
  42. ## Emphasis
  43. ```no-highlight
  44. Emphasis, aka italics, with *asterisks* or _underscores_.
  45. Strong emphasis, aka bold, with **asterisks** or __underscores__.
  46. Combined emphasis with **asterisks and _underscores_**.
  47. Strikethrough uses two tildes. ~~Scratch this.~~
  48. ```
  49. Emphasis, aka italics, with *asterisks* or _underscores_.
  50. Strong emphasis, aka bold, with **asterisks** or __underscores__.
  51. Combined emphasis with **asterisks and _underscores_**.
  52. Strikethrough uses two tildes. ~~Scratch this.~~
  53. <a name="lists"/>
  54. ## Lists
  55. ```no-highlight
  56. 1. First ordered list item
  57. 2. Another item
  58. * Unordered sub-list.
  59. 1. Actual numbers don't matter, just that it's a number
  60. 1. Ordered sub-list
  61. 4. And another item.
  62. Some text that should be aligned with the above item.
  63. * Unordered list can use asterisks
  64. - Or minuses
  65. + Or pluses
  66. ```
  67. 1. First ordered list item
  68. 2. Another item
  69. * Unordered sub-list.
  70. 1. Actual numbers don't matter, just that it's a number
  71. 1. Ordered sub-list
  72. 4. And another item.
  73. Some text that should be aligned with the above item.
  74. * Unordered list can use asterisks
  75. - Or minuses
  76. + Or pluses
  77. <a name="links"/>
  78. ## Links
  79. There are two ways to create links.
  80. ```no-highlight
  81. [I'm an inline-style link](https://www.google.com)
  82. [I'm a reference-style link][Arbitrary case-insensitive reference text]
  83. [You can use numbers for reference-style link definitions][1]
  84. Or leave it empty and use the [link text itself][]
  85. Some text to show that the reference links can follow later.
  86. [arbitrary case-insensitive reference text]: https://www.mozilla.org
  87. [1]: http://slashdot.org
  88. [link text itself]: http://www.reddit.com
  89. ```
  90. [I'm an inline-style link](https://www.google.com)
  91. [I'm a reference-style link][Arbitrary case-insensitive reference text]
  92. [You can use numbers for reference-style link definitions][1]
  93. Or leave it empty and use the [link text itself][]
  94. Some text to show that the reference links can follow later.
  95. [arbitrary case-insensitive reference text]: https://www.mozilla.org
  96. [1]: http://slashdot.org
  97. [link text itself]: http://www.reddit.com
  98. <a name="images"/>
  99. ## Images
  100. ```no-highlight
  101. Here's our logo (hover to see the title text):
  102. Inline-style:
  103. ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
  104. Reference-style:
  105. ![alt text][logo]
  106. [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
  107. ```
  108. Here's our logo (hover to see the title text):
  109. Inline-style:
  110. ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
  111. Reference-style:
  112. ![alt text][logo]
  113. [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
  114. <a name="code"/>
  115. ## Code and Syntax Highlighting
  116. 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).
  117. ```no-highlight
  118. Inline `code` has `back-ticks around` it.
  119. ```
  120. Inline `code` has `back-ticks around` it.
  121. 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.
  122. ```no-highlight
  123. ```javascript
  124. var s = "JavaScript syntax highlighting";
  125. alert(s);
  126. ```
  127. ```python
  128. s = "Python syntax highlighting"
  129. print s
  130. ```
  131. ```
  132. No language indicated, so no syntax highlighting.
  133. But let's throw in a <b>tag</b>.
  134. ```
  135. ```
  136. ```javascript
  137. var s = "JavaScript syntax highlighting";
  138. alert(s);
  139. ```
  140. ```python
  141. s = "Python syntax highlighting"
  142. print s
  143. ```
  144. ```
  145. No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
  146. But let's throw in a <b>tag</b>.
  147. ```
  148. (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.)
  149. 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).
  150. <a name="tables"/>
  151. ## Tables
  152. 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.
  153. ```no-highlight
  154. Colons can be used to align columns.
  155. | Tables | Are | Cool |
  156. | ------------- |:-------------:| -----:|
  157. | col 3 is | right-aligned | $1600 |
  158. | col 2 is | centered | $12 |
  159. | zebra stripes | are neat | $1 |
  160. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
  161. Markdown | Less | Pretty
  162. --- | --- | ---
  163. *Still* | `renders` | **nicely**
  164. 1 | 2 | 3
  165. ```
  166. Colons can be used to align columns.
  167. | Tables | Are | Cool |
  168. | ------------- |:-------------:| -----:|
  169. | col 3 is | right-aligned | $1600 |
  170. | col 2 is | centered | $12 |
  171. | zebra stripes | are neat | $1 |
  172. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
  173. Markdown | Less | Pretty
  174. --- | --- | ---
  175. *Still* | `renders` | **nicely**
  176. 1 | 2 | 3
  177. <a name="blockquotes"/>
  178. ## Blockquotes
  179. ```no-highlight
  180. > Blockquotes are very handy in email to emulate reply text.
  181. > This line is part of the same quote.
  182. Quote break.
  183. > 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.
  184. ```
  185. > Blockquotes are very handy in email to emulate reply text.
  186. > This line is part of the same quote.
  187. Quote break.
  188. > 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.
  189. <a name="html"/>
  190. ## Inline HTML
  191. You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
  192. ```no-highlight
  193. <dl>
  194. <dt>Definition list</dt>
  195. <dd>Is something people use sometimes.</dd>
  196. <dt>Markdown in HTML</dt>
  197. <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
  198. </dl>
  199. ```
  200. <dl>
  201. <dt>Definition list</dt>
  202. <dd>Is something people use sometimes.</dd>
  203. <dt>Markdown in HTML</dt>
  204. <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
  205. </dl>
  206. <a name="hr"/>
  207. ## Horizontal Rule
  208. ```
  209. Three or more...
  210. ---
  211. Hyphens
  212. ***
  213. Asterisks
  214. ___
  215. Underscores
  216. ```
  217. Three or more...
  218. ---
  219. Hyphens
  220. ***
  221. Asterisks
  222. ___
  223. Underscores
  224. <a name="lines"/>
  225. ## Line Breaks
  226. 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.
  227. Here are some things to try out:
  228. ```
  229. Here's a line for us to start with.
  230. This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
  231. This line is also a separate paragraph, but...
  232. This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
  233. ```
  234. Here's a line for us to start with.
  235. This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
  236. This line is also begins a separate paragraph, but...
  237. This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
  238. (Technical note: *Markdown Here* uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
  239. <a name="videos"/>
  240. ## Youtube videos
  241. They can't be added directly but you can add an image with a link to the video like this:
  242. ```no-highlight
  243. <a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
  244. " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
  245. alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>
  246. ```
  247. Or, in pure Markdown, but losing the image sizing and border:
  248. ```no-highlight
  249. [![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)
  250. ```
  251. ## Coda
  252. Originally borrowed from [Joshua Pekera's excellent template](https://gist.github.com/joshuapekera/5730539/), and since much amended. 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/).