(In this example, leading and trailing spaces are shown with with dots: ⋅)
99 |
100 |
1. First ordered list item
101 | 2. Another item
102 | ⋅⋅* Unordered sub-list.
103 | 1. Actual numbers don't matter, just that it's a number
104 | ⋅⋅1. Ordered sub-list
105 | 4. And another item.
106 |
107 | ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
108 |
109 | ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
110 | ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
111 | ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
112 |
113 | * Unordered list can use asterisks
114 | - Or minuses
115 | + Or pluses
116 |
117 |
118 |
119 |
First ordered list item
120 |
Another item
121 |
122 |
123 |
Unordered sub-list.
124 |
125 |
Actual numbers don't matter, just that it's a number
126 |
127 |
128 |
Ordered sub-list
129 |
130 |
And another item.
131 |
132 |
You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
133 |
134 |
To have a line break without a paragraph, you will need to use two trailing spaces.
135 | Note that this line is separate, but within the same paragraph.
136 | (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
137 |
138 |
139 |
140 |
Unordered list can use asterisks
141 |
Or minuses
142 |
Or pluses
143 |
144 |
145 |
146 |
foo
147 |
148 |
149 |
bar
150 |
151 |
152 |
baz
153 |
154 |
155 |
faz
156 |
157 |
158 |
159 |
foo2
160 |
161 |
162 |
163 |
foo
164 |
165 |
166 |
bar
167 |
168 |
169 |
baz
170 |
171 |
172 |
faz
173 |
174 |
175 |
176 |
foo2
177 |
178 |
179 |
180 |
foo
181 |
182 |
183 |
bar
184 |
185 |
186 |
baz
187 |
188 |
189 |
faz
190 |
191 |
192 |
193 |
194 |
195 |
196 |
foo
197 |
198 |
199 |
bar
200 |
201 |
202 |
baz
203 |
204 |
205 |
faz
206 |
207 |
208 |
209 |
210 |
211 |
212 |
Lists in a list item:
213 |
214 |
215 |
Indented four spaces.
216 |
217 |
218 |
indented eight spaces.
219 |
220 |
Four spaces again.
221 |
222 |
Multiple paragraphs in a list items:
223 | It's best to indent the paragraphs four spaces
224 | You can get away with three, but it can get
225 | confusing when you nest other things.
226 | Stick to four.
227 |
228 |
We indented the first line an extra space to align
229 | it with these paragraphs. In real use, we might do
230 | that to the entire list so that all items line up.
231 |
232 |
This paragraph is still part of the list item, but it looks messy to humans. So it's a good idea to wrap your nested paragraphs manually, as we did with the first two.
233 |
Blockquotes in a list item:
234 |
235 |
236 |
Skip a line and
237 | indent the >'s four spaces.
238 |
239 |
Preformatted text in a list item:
240 |
241 |
Skip a line and indent eight spaces.
242 | That's four spaces for the list
243 | and four to trigger the code block.
244 |
[I'm an inline-style link](https://www.google.com)
258 |
259 | [I'm an inline-style link with title](https://www.google.com "Google's Homepage")
260 |
261 | [I'm a reference-style link][Arbitrary case-insensitive reference text]
262 |
263 | [I'm a relative reference to a repository file](../blob/master/LICENSE)
264 |
265 | [You can use numbers for reference-style link definitions][1]
266 |
267 | Or leave it empty and use the [link text itself]
268 |
269 | Some text to show that the reference links can follow later.
270 |
271 | [arbitrary case-insensitive reference text]: https://www.mozilla.org
272 | [1]: http://slashdot.org
273 | [link text itself]: http://www.reddit.com
274 |
Here's our logo (hover to see the title text):
295 |
296 | Inline-style:
297 | 
298 |
299 | Reference-style:
300 | ![alt text][logo]
301 |
302 | [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
303 |
Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.
325 |
326 |
```javascript
327 | var s = "JavaScript syntax highlighting";
328 | alert(s);
329 | ```
330 |
331 | ```python
332 | s = "Python syntax highlighting"
333 | print s
334 | ```
335 |
336 | ```
337 | No language indicated, so no syntax highlighting.
338 | But let's throw in a <b>tag</b>.
339 | ```
340 |
341 |
342 |
var s ="JavaScript syntax highlighting";
343 | alert(s);
344 |
345 |
s ="Python syntax highlighting"
346 | print s
347 |
348 |
No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
349 | But let's throw in a <b>tag</b>.
350 |
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.
357 |
358 |
Colons can be used to align columns.
359 |
360 | | Tables | Are | Cool |
361 | | ------------- |:-------------:| -----:|
362 | | col 3 is | right-aligned | |
363 | | col 2 is | centered | |
364 | | zebra stripes | are neat | |
365 |
366 | The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
367 |
368 | Markdown | Less | Pretty
369 | --- | --- | ---
370 | *Still* | `renders` | **nicely**
371 | 1 | 2 | 3
372 |
373 |
374 |
Colons can be used to align columns.
375 |
376 |
377 |
378 |
Tables
379 |
Are
380 |
Cool
381 |
382 |
383 |
384 |
col 3 is
385 |
right-aligned
386 |
387 |
388 |
389 |
col 2 is
390 |
centered
391 |
392 |
393 |
394 |
zebra stripes
395 |
are neat
396 |
397 |
398 |
399 |
400 |
The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
> Blockquotes are very handy in email to emulate reply text.
426 | > This line is part of the same quote.
427 |
428 | Quote break.
429 |
430 | > 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.
431 |
432 |
433 |
434 |
Blockquotes are very handy in email to emulate reply text.
435 | This line is part of the same quote.
436 |
437 |
438 |
Quote break.
439 |
440 |
441 |
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 putMarkdown into a blockquote.
My basic recommendation for learning how line breaks work is to experiment and discover -- hit <Enter> 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.
505 |
506 |
Here are some things to try out:
507 |
508 |
Here's a line for us to start with.
509 |
510 | This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
511 |
512 | This line is also a separate paragraph, but...
513 | This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
514 |
515 |
516 |
Here's a line for us to start with.
517 |
518 |
This line is separated from the one above by two newlines, so it will be a separate paragraph.
519 |
520 |
This line is also begins a separate paragraph, but...
521 | This line is only separated by a single newline, so it's a separate line in the same paragraph.
522 |
523 |
(Technical note: Markdown Here uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
Just a note, I've found that I can't test my markdown parser vs others.
560 | For example, both markdown.js and showdown code blocks in lists wrong. They're
561 | also completely [inconsistent][test] with regards to paragraphs in list items.
562 |
563 |
A link. Not anymore.
564 |
565 | This will make me fail the test because
566 | markdown.js doesnt acknowledge arbitrary html blocks =/
567 |
568 |
569 |
List Item 1
570 |
List Item 2
571 |
572 |
573 |
New List Item 1
574 | Hi, this is a list item.
575 |
New List Item 2
576 | Another item
577 | Code goes here.
578 | Lots of it...
579 |
New List Item 3
580 | The last item
581 |
582 |
List Item 3
583 | The final item.
584 |
List Item 4
585 | The real final item.
586 |
587 |
588 |
Paragraph.
589 |
590 |
591 |
592 |
bq Item 1
593 |
bq Item 2
594 |
595 |
596 |
New bq Item 1
597 |
New bq Item 2
598 | Text here
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
Another blockquote!
607 | I really need to get
608 | more creative with
609 | mockup text..
610 | markdown.js breaks here again
Note: This document is itself written using Markdown; you
848 | can [see the source for it by adding '.text' to the URL][src].
849 |
850 |
[src]: /projects/markdown/syntax.text
851 |
852 |
853 |
854 |
Overview
855 |
856 |
Philosophy
857 |
858 |
Markdown is intended to be as easy-to-read and easy-to-write as is feasible.
859 |
860 |
Readability, however, is emphasized above all else. A Markdown-formatted
861 | document should be publishable as-is, as plain text, without looking
862 | like it's been marked up with tags or formatting instructions. While
863 | Markdown's syntax has been influenced by several existing text-to-HTML
864 | filters -- including Setext, [atx] [2], [Textile] [3], [reStructuredText] [4],
865 | [Grutatext] [5], and [EtText] [6] -- the single biggest source of
866 | inspiration for Markdown's syntax is the format of plain text email.
To this end, Markdown's syntax is comprised entirely of punctuation
876 | characters, which punctuation characters have been carefully chosen so
877 | as to look like what they mean. E.g., asterisks around a word actually
878 | look like *emphasis*. Markdown lists look like, well, lists. Even
879 | blockquotes look like quoted passages of text, assuming you've ever
880 | used email.
881 |
882 |
Inline HTML
883 |
884 |
Markdown's syntax is intended for one purpose: to be used as a
885 | format for writing for the web.
886 |
887 |
Markdown is not a replacement for HTML, or even close to it. Its
888 | syntax is very small, corresponding only to a very small subset of
889 | HTML tags. The idea is not to create a syntax that makes it easier
890 | to insert HTML tags. In my opinion, HTML tags are already easy to
891 | insert. The idea for Markdown is to make it easy to read, write, and
892 | edit prose. HTML is a publishing format; Markdown is a writing
893 | format. Thus, Markdown's formatting syntax only addresses issues that
894 | can be conveyed in plain text.
895 |
896 |
For any markup that is not covered by Markdown's syntax, you simply
897 | use HTML itself. There's no need to preface it or delimit it to
898 | indicate that you're switching from Markdown to HTML; you just use
899 | the tags.
900 |
901 |
The only restrictions are that block-level HTML elements -- e.g. <div>,
902 | <table>, <pre>, <p>, etc. -- must be separated from surrounding
903 | content by blank lines, and the start and end tags of the block should
904 | not be indented with tabs or spaces. Markdown is smart enough not
905 | to add extra (unwanted) <p> tags around HTML block-level tags.
906 |
907 |
For example, to add an HTML table to a Markdown article:
908 |
909 |
This is a regular paragraph.
910 |
911 | <table>
912 | <tr>
913 | <td>Foo</td>
914 | </tr>
915 | </table>
916 |
917 | This is another regular paragraph.
918 |
919 |
920 |
Note that Markdown formatting syntax is not processed within block-level
921 | HTML tags. E.g., you can't use Markdown-style *emphasis* inside an
922 | HTML block.
923 |
924 |
Span-level HTML tags -- e.g. <span>, <cite>, or <del> -- can be
925 | used anywhere in a Markdown paragraph, list item, or header. If you
926 | want, you can even use HTML tags instead of Markdown formatting; e.g. if
927 | you'd prefer to use HTML <a> or <img> tags instead of Markdown's
928 | link or image syntax, go right ahead.
929 |
930 |
Unlike block-level HTML tags, Markdown syntax is processed within
931 | span-level tags.
932 |
933 |
Automatic Escaping for Special Characters
934 |
935 |
In HTML, there are two characters that demand special treatment: <
936 | and &. Left angle brackets are used to start tags; ampersands are
937 | used to denote HTML entities. If you want to use them as literal
938 | characters, you must escape them as entities, e.g. <, and
939 | &.
940 |
941 |
Ampersands in particular are bedeviling for web writers. If you want to
942 | write about 'AT&T', you need to write 'AT&T'. You even need to
943 | escape ampersands within URLs. Thus, if you want to link to:
in your anchor tag href attribute. Needless to say, this is easy to
954 | forget, and is probably the single most common source of HTML validation
955 | errors in otherwise well-marked-up web sites.
956 |
957 |
Markdown allows you to use these characters naturally, taking care of
958 | all the necessary escaping for you. If you use an ampersand as part of
959 | an HTML entity, it remains unchanged; otherwise it will be translated
960 | into &.
961 |
962 |
So, if you want to include a copyright symbol in your article, you can write:
and Markdown will leave it alone. But if you write:
968 |
969 |
AT&T
970 |
971 |
972 |
Markdown will translate it to:
973 |
974 |
AT&T
975 |
976 |
977 |
Similarly, because Markdown supports inline HTML, if you use
978 | angle brackets as delimiters for HTML tags, Markdown will treat them as
979 | such. But if you write:
980 |
981 |
4 < 5
982 |
983 |
984 |
Markdown will translate it to:
985 |
986 |
4 < 5
987 |
988 |
989 |
However, inside Markdown code spans and blocks, angle brackets and
990 | ampersands are always encoded automatically. This makes it easy to use
991 | Markdown to write about HTML code. (As opposed to raw HTML, which is a
992 | terrible format for writing about HTML syntax, because every single <
993 | and & in your example code needs to be escaped.)
994 |
995 |
996 |
997 |
Block Elements
998 |
999 |
Paragraphs and Line Breaks
1000 |
1001 |
A paragraph is simply one or more consecutive lines of text, separated
1002 | by one or more blank lines. (A blank line is any line that looks like a
1003 | blank line -- a line containing nothing but spaces or tabs is considered
1004 | blank.) Normal paragraphs should not be intended with spaces or tabs.
1005 |
1006 |
The implication of the "one or more consecutive lines of text" rule is
1007 | that Markdown supports "hard-wrapped" text paragraphs. This differs
1008 | significantly from most other text-to-HTML formatters (including Movable
1009 | Type's "Convert Line Breaks" option) which translate every line break
1010 | character in a paragraph into a <br /> tag.
1011 |
1012 |
When you do want to insert a <br /> break tag using Markdown, you
1013 | end a line with two or more spaces, then type return.
1014 |
1015 |
Yes, this takes a tad more effort to create a <br />, but a simplistic
1016 | "every line break is a <br />" rule wouldn't work for Markdown.
1017 | Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l]
1018 | work best -- and look better -- when you format them with hard breaks.
1019 |
1020 |
[bq]: #blockquote
1021 | [l]: #list
1022 |
1023 |
Headers
1024 |
1025 |
Markdown supports two styles of headers, Setext and [atx] [2].
1026 |
1027 |
Setext-style headers are "underlined" using equal signs (for first-level
1028 | headers) and dashes (for second-level headers). For example:
1029 |
1030 |
This is an H1
1031 | =============
1032 |
1033 | This is an H2
1034 | -------------
1035 |
1036 |
1037 |
Any number of underlining ='s or -'s will work.
1038 |
1039 |
Atx-style headers use 1-6 hash characters at the start of the line,
1040 | corresponding to header levels 1-6. For example:
1041 |
1042 |
# This is an H1
1043 |
1044 | ## This is an H2
1045 |
1046 | ###### This is an H6
1047 |
1048 |
1049 |
Optionally, you may "close" atx-style headers. This is purely
1050 | cosmetic -- you can use this if you think it looks better. The
1051 | closing hashes don't even need to match the number of hashes
1052 | used to open the header. (The number of opening hashes
1053 | determines the header level.) :
1054 |
1055 |
# This is an H1 #
1056 |
1057 | ## This is an H2 ##
1058 |
1059 | ### This is an H3 ######
1060 |
1061 |
1062 |
Blockquotes
1063 |
1064 |
Markdown uses email-style > characters for blockquoting. If you're
1065 | familiar with quoting passages of text in an email message, then you
1066 | know how to create a blockquote in Markdown. It looks best if you hard
1067 | wrap the text and put a > before every line:
1068 |
1069 |
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
1070 | > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
1071 | > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
1072 | >
1073 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
1074 | > id sem consectetuer libero luctus adipiscing.
1075 |
1076 |
1077 |
Markdown allows you to be lazy and only put the > before the first
1078 | line of a hard-wrapped paragraph:
1079 |
1080 |
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
1081 | consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
1082 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
1083 |
1084 | > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
1085 | id sem consectetuer libero luctus adipiscing.
1086 |
1087 |
1088 |
Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
1089 | adding additional levels of >:
1090 |
1091 |
> This is the first level of quoting.
1092 | >
1093 | > > This is nested blockquote.
1094 | >
1095 | > Back to the first level.
1096 |
1097 |
1098 |
Blockquotes can contain other Markdown elements, including headers, lists,
1099 | and code blocks:
1100 |
1101 |
> ## This is a header.
1102 | >
1103 | > 1. This is the first list item.
1104 | > 2. This is the second list item.
1105 | >
1106 | > Here's some example code:
1107 | >
1108 | > return shell_exec("echo $input | $markdown_script");
1109 |
1110 |
1111 |
Any decent text editor should make email-style quoting easy. For
1112 | example, with BBEdit, you can make a selection and choose Increase
1113 | Quote Level from the Text menu.
1114 |
1115 |
Lists
1116 |
1117 |
Markdown supports ordered (numbered) and unordered (bulleted) lists.
1118 |
1119 |
Unordered lists use asterisks, pluses, and hyphens -- interchangably
1120 | -- as list markers:
1121 |
1122 |
* Red
1123 | * Green
1124 | * Blue
1125 |
1126 |
1127 |
is equivalent to:
1128 |
1129 |
+ Red
1130 | + Green
1131 | + Blue
1132 |
1133 |
1134 |
and:
1135 |
1136 |
- Red
1137 | - Green
1138 | - Blue
1139 |
1140 |
1141 |
Ordered lists use numbers followed by periods:
1142 |
1143 |
1. Bird
1144 | 2. McHale
1145 | 3. Parish
1146 |
1147 |
1148 |
It's important to note that the actual numbers you use to mark the
1149 | list have no effect on the HTML output Markdown produces. The HTML
1150 | Markdown produces from the above list is:
If you instead wrote the list in Markdown like this:
1160 |
1161 |
1. Bird
1162 | 1. McHale
1163 | 1. Parish
1164 |
1165 |
1166 |
or even:
1167 |
1168 |
3. Bird
1169 | 1. McHale
1170 | 8. Parish
1171 |
1172 |
1173 |
you'd get the exact same HTML output. The point is, if you want to,
1174 | you can use ordinal numbers in your ordered Markdown lists, so that
1175 | the numbers in your source match the numbers in your published HTML.
1176 | But if you want to be lazy, you don't have to.
1177 |
1178 |
If you do use lazy list numbering, however, you should still start the
1179 | list with the number 1. At some point in the future, Markdown may support
1180 | starting ordered lists at an arbitrary number.
1181 |
1182 |
List markers typically start at the left margin, but may be indented by
1183 | up to three spaces. List markers must be followed by one or more spaces
1184 | or a tab.
1185 |
1186 |
To make lists look nice, you can wrap items with hanging indents:
1187 |
1188 |
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
1189 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
1190 | viverra nec, fringilla in, laoreet vitae, risus.
1191 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
1192 | Suspendisse id sem consectetuer libero luctus adipiscing.
1193 |
1194 |
1195 |
But if you want to be lazy, you don't have to:
1196 |
1197 |
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
1198 | Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
1199 | viverra nec, fringilla in, laoreet vitae, risus.
1200 | * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
1201 | Suspendisse id sem consectetuer libero luctus adipiscing.
1202 |
1203 |
1204 |
If list items are separated by blank lines, Markdown will wrap the
1205 | items in <p> tags in the HTML output. For example, this input:
List items may consist of multiple paragraphs. Each subsequent
1235 | paragraph in a list item must be intended by either 4 spaces
1236 | or one tab:
1237 |
1238 |
1. This is a list item with two paragraphs. Lorem ipsum dolor
1239 | sit amet, consectetuer adipiscing elit. Aliquam hendrerit
1240 | mi posuere lectus.
1241 |
1242 | Vestibulum enim wisi, viverra nec, fringilla in, laoreet
1243 | vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
1244 | sit amet velit.
1245 |
1246 | 2. Suspendisse id sem consectetuer libero luctus adipiscing.
1247 |
1248 |
1249 |
It looks nice if you indent every line of the subsequent
1250 | paragraphs, but here again, Markdown will allow you to be
1251 | lazy:
1252 |
1253 |
* This is a list item with two paragraphs.
1254 |
1255 | This is the second paragraph in the list item. You're
1256 | only required to indent the first line. Lorem ipsum dolor
1257 | sit amet, consectetuer adipiscing elit.
1258 |
1259 | * Another item in the same list.
1260 |
1261 |
1262 |
To put a blockquote within a list item, the blockquote's >
1263 | delimiters need to be indented:
1264 |
1265 |
* A list item with a blockquote:
1266 |
1267 | > This is a blockquote
1268 | > inside a list item.
1269 |
1270 |
1271 |
To put a code block within a list item, the code block needs
1272 | to be indented twice -- 8 spaces or two tabs:
1273 |
1274 |
* A list item with a code block:
1275 |
1276 | <code goes here>
1277 |
1278 |
1279 |
It's worth noting that it's possible to trigger an ordered list by
1280 | accident, by writing something like this:
1281 |
1282 |
1986. What a great season.
1283 |
1284 |
1285 |
In other words, a number-period-space sequence at the beginning of a
1286 | line. To avoid this, you can backslash-escape the period:
1287 |
1288 |
1986\. What a great season.
1289 |
1290 |
1291 |
Code Blocks
1292 |
1293 |
Pre-formatted code blocks are used for writing about programming or
1294 | markup source code. Rather than forming normal paragraphs, the lines
1295 | of a code block are interpreted literally. Markdown wraps a code block
1296 | in both <pre> and <code> tags.
1297 |
1298 |
To produce a code block in Markdown, simply indent every line of the
1299 | block by at least 4 spaces or 1 tab. For example, given this input:
1300 |
1301 |
This is a normal paragraph:
1302 |
1303 | This is a code block.
1304 |
1305 |
1306 |
Markdown will generate:
1307 |
1308 |
<p>This is a normal paragraph:</p>
1309 |
1310 | <pre><code>This is a code block.
1311 | </code></pre>
1312 |
1313 |
1314 |
One level of indentation -- 4 spaces or 1 tab -- is removed from each
1315 | line of the code block. For example, this:
1316 |
1317 |
Here is an example of AppleScript:
1318 |
1319 | tell application "Foo"
1320 | beep
1321 | end tell
1322 |
1323 |
1324 |
will turn into:
1325 |
1326 |
<p>Here is an example of AppleScript:</p>
1327 |
1328 | <pre><code>tell application "Foo"
1329 | beep
1330 | end tell
1331 | </code></pre>
1332 |
1333 |
1334 |
A code block continues until it reaches a line that is not indented
1335 | (or the end of the article).
1336 |
1337 |
Within a code block, ampersands (&) and angle brackets (< and >)
1338 | are automatically converted into HTML entities. This makes it very
1339 | easy to include example HTML source code using Markdown -- just paste
1340 | it and indent it, and Markdown will handle the hassle of encoding the
1341 | ampersands and angle brackets. For example, this:
Regular Markdown syntax is not processed within code blocks. E.g.,
1357 | asterisks are just literal asterisks within a code block. This means
1358 | it's also easy to use Markdown to write about Markdown's own syntax.
1359 |
1360 |
Horizontal Rules
1361 |
1362 |
You can produce a horizontal rule tag (<hr />) by placing three or
1363 | more hyphens, asterisks, or underscores on a line by themselves. If you
1364 | wish, you may use spaces between the hyphens or asterisks. Each of the
1365 | following lines will produce a horizontal rule:
Markdown supports two style of links: inline and reference.
1387 |
1388 |
In both styles, the link text is delimited by [square brackets].
1389 |
1390 |
To create an inline link, use a set of regular parentheses immediately
1391 | after the link text's closing square bracket. Inside the parentheses,
1392 | put the URL where you want the link to point, along with an optional
1393 | title for the link, surrounded in quotes. For example:
1394 |
1395 |
This is [an example](http://example.com/ "Title") inline link.
1396 |
1397 | [This link](http://example.net/) has no title attribute.
1398 |
1399 |
1400 |
Will produce:
1401 |
1402 |
<p>This is <a href="http://example.com/" title="Title">
1403 | an example</a> inline link.</p>
1404 |
1405 | <p><a href="http://example.net/">This link</a> has no
1406 | title attribute.</p>
1407 |
1408 |
1409 |
If you're referring to a local resource on the same server, you can
1410 | use relative paths:
1411 |
1412 |
See my [About](/about/) page for details.
1413 |
1414 |
1415 |
Reference-style links use a second set of square brackets, inside
1416 | which you place a label of your choosing to identify the link:
1417 |
1418 |
This is [an example][id] reference-style link.
1419 |
1420 |
1421 |
You can optionally use a space to separate the sets of brackets:
1422 |
1423 |
This is [an example] [id] reference-style link.
1424 |
1425 |
1426 |
Then, anywhere in the document, you define your link label like this,
1427 | on a line by itself:
1428 |
1429 |
[id]: http://example.com/ "Optional Title Here"
1430 |
1431 |
1432 |
That is:
1433 |
1434 |
1435 |
Square brackets containing the link identifier (optionally
1436 | indented from the left margin using up to three spaces);
1437 |
followed by a colon;
1438 |
followed by one or more spaces (or tabs);
1439 |
followed by the URL for the link;
1440 |
optionally followed by a title attribute for the link, enclosed
1441 | in double or single quotes.
1442 |
1443 |
1444 |
The link URL may, optionally, be surrounded by angle brackets:
1445 |
1446 |
[id]: <http://example.com/> "Optional Title Here"
1447 |
1448 |
1449 |
You can put the title attribute on the next line and use extra spaces
1450 | or tabs for padding, which tends to look better with longer URLs:
1451 |
1452 |
[id]: http://example.com/longish/path/to/resource/here
1453 | "Optional Title Here"
1454 |
1455 |
1456 |
Link definitions are only used for creating links during Markdown
1457 | processing, and are stripped from your document in the HTML output.
1458 |
1459 |
Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are not case sensitive. E.g. these two links:
1460 |
1461 |
[link text][a]
1462 | [link text][A]
1463 |
1464 |
1465 |
are equivalent.
1466 |
1467 |
The implicit link name shortcut allows you to omit the name of the
1468 | link, in which case the link text itself is used as the name.
1469 | Just use an empty set of square brackets -- e.g., to link the word
1470 | "Google" to the google.com web site, you could simply write:
1471 |
1472 |
[Google][]
1473 |
1474 |
1475 |
And then define the link:
1476 |
1477 |
[Google]: http://google.com/
1478 |
1479 |
1480 |
Because link names may contain spaces, this shortcut even works for
1481 | multiple words in the link text:
1482 |
1483 |
Visit [Daring Fireball][] for more information.
1484 |
Link definitions can be placed anywhere in your Markdown document. I
1492 | tend to put them immediately after each paragraph in which they're
1493 | used, but if you want, you can put them all at the end of your
1494 | document, sort of like footnotes.
1495 |
1496 |
Here's an example of reference links in action:
1497 |
1498 |
I get 10 times more traffic from [Google] [1] than from
1499 | [Yahoo] [2] or [MSN] [3].
1500 |
1501 | [1]: http://google.com/ "Google"
1502 | [2]: http://search.yahoo.com/ "Yahoo Search"
1503 | [3]: http://search.msn.com/ "MSN Search"
1504 |
1505 |
1506 |
Using the implicit link name shortcut, you could instead write:
1507 |
1508 |
I get 10 times more traffic from [Google][] than from
1509 | [Yahoo][] or [MSN][].
1510 |
1511 | [google]: http://google.com/ "Google"
1512 | [yahoo]: http://search.yahoo.com/ "Yahoo Search"
1513 | [msn]: http://search.msn.com/ "MSN Search"
1514 |
1515 |
1516 |
Both of the above examples will produce the following HTML output:
1517 |
1518 |
<p>I get 10 times more traffic from <a href="http://google.com/"
1519 | title="Google">Google</a> than from
1520 | <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
1521 | or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
1522 |
1523 |
1524 |
For comparison, here is the same paragraph written using
1525 | Markdown's inline link style:
1526 |
1527 |
I get 10 times more traffic from [Google](http://google.com/ "Google")
1528 | than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
1529 | [MSN](http://search.msn.com/ "MSN Search").
1530 |
1531 |
1532 |
The point of reference-style links is not that they're easier to
1533 | write. The point is that with reference-style links, your document
1534 | source is vastly more readable. Compare the above examples: using
1535 | reference-style links, the paragraph itself is only 81 characters
1536 | long; with inline-style links, it's 176 characters; and as raw HTML,
1537 | it's 234 characters. In the raw HTML, there's more markup than there
1538 | is text.
1539 |
1540 |
With Markdown's reference-style links, a source document much more
1541 | closely resembles the final output, as rendered in a browser. By
1542 | allowing you to move the markup-related metadata out of the paragraph,
1543 | you can add links without interrupting the narrative flow of your
1544 | prose.
1545 |
1546 |
Emphasis
1547 |
1548 |
Markdown treats asterisks (*) and underscores (_) as indicators of
1549 | emphasis. Text wrapped with one * or _ will be wrapped with an
1550 | HTML <em> tag; double *'s or _'s will be wrapped with an HTML
1551 | <strong> tag. E.g., this input:
You can use whichever style you prefer; the lone restriction is that
1574 | the same character must be used to open and close an emphasis span.
1575 |
1576 |
Emphasis can be used in the middle of a word:
1577 |
1578 |
un*fucking*believable
1579 |
1580 |
1581 |
But if you surround an * or _ with spaces, it'll be treated as a
1582 | literal asterisk or underscore.
1583 |
1584 |
To produce a literal asterisk or underscore at a position where it
1585 | would otherwise be used as an emphasis delimiter, you can backslash
1586 | escape it:
1587 |
1588 |
\*this text is surrounded by literal asterisks\*
1589 |
1590 |
1591 |
Code
1592 |
1593 |
To indicate a span of code, wrap it with backtick quotes (`).
1594 | Unlike a pre-formatted code block, a code span indicates code within a
1595 | normal paragraph. For example:
1596 |
1597 |
Use the `printf()` function.
1598 |
1599 |
1600 |
will produce:
1601 |
1602 |
<p>Use the <code>printf()</code> function.</p>
1603 |
1604 |
1605 |
To include a literal backtick character within a code span, you can use
1606 | multiple backticks as the opening and closing delimiters:
1607 |
1608 |
``There is a literal backtick (`) here.``
1609 |
1610 |
1611 |
which will produce this:
1612 |
1613 |
<p><code>There is a literal backtick (`) here.</code></p>
1614 |
1615 |
1616 |
The backtick delimiters surrounding a code span may include spaces --
1617 | one after the opening, one before the closing. This allows you to place
1618 | literal backtick characters at the beginning or end of a code span:
1619 |
1620 |
A single backtick in a code span: `` ` ``
1621 |
1622 | A backtick-delimited string in a code span: `` `foo` ``
1623 |
1624 |
1625 |
will produce:
1626 |
1627 |
<p>A single backtick in a code span: <code>`</code></p>
1628 |
1629 | <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
1630 |
1631 |
1632 |
With a code span, ampersands and angle brackets are encoded as HTML
1633 | entities automatically, which makes it easy to include example HTML
1634 | tags. Markdown will turn this:
1635 |
1636 |
Please don't use any `<blink>` tags.
1637 |
1638 |
1639 |
into:
1640 |
1641 |
<p>Please don't use any <code><blink></code> tags.</p>
1642 |
1643 |
1644 |
You can write this:
1645 |
1646 |
`—` is the decimal-encoded equivalent of `—`.
1647 |
1648 |
1649 |
to produce:
1650 |
1651 |
<p><code>&#8212;</code> is the decimal-encoded
1652 | equivalent of <code>&mdash;</code>.</p>
1653 |
1654 |
1655 |
Images
1656 |
1657 |
Admittedly, it's fairly difficult to devise a "natural" syntax for
1658 | placing images into a plain text document format.
1659 |
1660 |
Markdown uses an image syntax that is intended to resemble the syntax
1661 | for links, allowing for two styles: inline and reference.
followed by a set of square brackets, containing the alt
1675 | attribute text for the image;
1676 |
followed by a set of parentheses, containing the URL or path to
1677 | the image, and an optional title attribute enclosed in double
1678 | or single quotes.
1679 |
1680 |
1681 |
Reference-style image syntax looks like this:
1682 |
1683 |
![Alt text][id]
1684 |
1685 |
1686 |
Where "id" is the name of a defined image reference. Image references
1687 | are defined using syntax identical to link references:
1688 |
1689 |
[id]: url/to/image "Optional title attribute"
1690 |
1691 |
1692 |
As of this writing, Markdown has no syntax for specifying the
1693 | dimensions of an image; if this is important to you, you can simply
1694 | use regular HTML <img> tags.
1695 |
1696 |
1697 |
1698 |
Miscellaneous
1699 |
1700 |
Automatic Links
1701 |
1702 |
Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:
Automatic links for email addresses work similarly, except that
1713 | Markdown will also perform a bit of randomized decimal and hex
1714 | entity-encoding to help obscure your address from address-harvesting
1715 | spambots. For example, Markdown will turn this:
which will render in a browser as a clickable link to "address@example.com".
1729 |
1730 |
(This sort of entity-encoding trick will indeed fool many, if not
1731 | most, address-harvesting bots, but it definitely won't fool all of
1732 | them. It's better than nothing, but an address published in this way
1733 | will probably eventually start receiving spam.)
1734 |
1735 |
Backslash Escapes
1736 |
1737 |
Markdown allows you to use backslash escapes to generate literal
1738 | characters which would otherwise have special meaning in Markdown's
1739 | formatting syntax. For example, if you wanted to surround a word with
1740 | literal asterisks (instead of an HTML <em> tag), you can backslashes
1741 | before the asterisks, like this:
1742 |
1743 |
\*literal asterisks\*
1744 |
1745 |
1746 |
Markdown provides backslash escapes for the following characters:
var gulp =require('gulp');
1857 | var myth =require('gulp-myth');
1858 |
1859 | gulp.task('default', function () {
1860 | return gulp.src('src/app.css')
1861 | .pipe(myth())
1862 | .pipe(gulp.dest('dist'));
1863 | });
1864 |
1865 | Fork me on GitHub
1866 |
1867 |
1868 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "github-markdown-css",
3 | "version": "5.8.1",
4 | "description": "The minimal amount of CSS to replicate the GitHub Markdown style",
5 | "license": "MIT",
6 | "repository": "sindresorhus/github-markdown-css",
7 | "funding": "https://github.com/sponsors/sindresorhus",
8 | "author": {
9 | "name": "Sindre Sorhus",
10 | "email": "sindresorhus@gmail.com",
11 | "url": "https://sindresorhus.com"
12 | },
13 | "main": "github-markdown.css",
14 | "engines": {
15 | "node": ">=10"
16 | },
17 | "scripts": {
18 | "make:light": "github-markdown-css --no-use-fixture --type light > github-markdown-light.css",
19 | "make:dark": "github-markdown-css --no-use-fixture --type dark > github-markdown-dark.css",
20 | "make:auto": "github-markdown-css --no-use-fixture --type auto > github-markdown.css",
21 | "make": "npm run make:light && npm run make:dark && npm run make:auto"
22 | },
23 | "files": [
24 | "github-markdown.css",
25 | "github-markdown-dark.css",
26 | "github-markdown-light.css"
27 | ],
28 | "keywords": [
29 | "browser",
30 | "github",
31 | "markdown",
32 | "md",
33 | "css",
34 | "style",
35 | "stylesheet"
36 | ],
37 | "devDependencies": {
38 | "generate-github-markdown-css": "^6.5.1"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # github-markdown-css
2 |
3 | > The minimal amount of CSS to replicate the GitHub Markdown style
4 |
5 | **The CSS is generated. Contributions should go to [this repo](https://github.com/sindresorhus/generate-github-markdown-css).**
6 |
7 | [](http://sindresorhus.com/github-markdown-css)
8 |
9 | ## [Demo](https://sindresorhus.com/github-markdown-css)
10 |
11 | ## Install
12 |
13 | Download [manually](https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css), from [CDNJS](https://cdnjs.com/libraries/github-markdown-css), or with npm:
14 |
15 | ```sh
16 | npm install github-markdown-css
17 | ```
18 |
19 | ## Usage
20 |
21 | Import the `github-markdown.css` file and add a `markdown-body` class to the container of your rendered Markdown and set a width for it. GitHub uses `980px` width and `45px` padding, and `15px` padding for mobile.
22 |
23 | ```html
24 |
25 |
26 |
41 |
42 |
Unicorns
43 |
All the things
44 |
45 | ```
46 |
47 | You can use [GitHub's `/markdown` API](https://docs.github.com/en/free-pro-team@latest/rest/reference/markdown) to turn Markdown into the HTML that GitHub generates, which works well with the CSS in this repo. Other Markdown parsers will mostly work with these styles too. To mimic how GitHub highlights code, you can use [`starry-night`](https://github.com/wooorm/starry-night) with your Markdown parser of choice.
48 |
49 | There are 3 themes provided in this package:
50 |
51 | - **github-markdown.css**: (default) Automatically switches between light and dark through [`@media (prefers-color-scheme)`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme).
52 | - **github-markdown-light.css**: Light-only.
53 | - **github-markdown-dark.css**: Dark-only.
54 |
55 | You may know that now GitHub supports more than 2 themes including `dark_dimmed`, `dark_high_contrast` and `colorblind` variants. If you want to try these themes, you can generate them on your own! See next section.
56 |
57 | ## How
58 |
59 | See [`generate-github-markdown-css`](https://github.com/sindresorhus/generate-github-markdown-css) for how it's generated and ability to generate your own.
60 |
61 | ## Troubleshooting
62 |
63 | If you encounter styling issues, like tables in dark mode rendering their fonts in black, the browser might uses [quirks mode](https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode) by accident.
64 |
65 | To avoid quirks mode, always include a doctype at the top of your page.
66 |
67 | ```html
68 |
69 |
70 | ```
71 |
72 | ## Dev
73 |
74 | Run `npm run make` to update the CSS.
75 |
--------------------------------------------------------------------------------