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.

432 lines
9.4 KiB

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