size: 2 KiB

1```
2[basic _link_][a_b_]
3
4[a_b_]: url
5.
6<p><a href="url">basic <em>link</em></a></p>
7```
8
9```
10![basic _image_][a_b_]
11
12[a_b_]: url
13.
14<p><img alt="basic image" src="url"></p>
15```
16
17```
18[link][]
19
20[link]: url
21.
22<p><a href="url">link</a></p>
23```
24
25```
26[link][]
27
28[link]:
29 url
30.
31<p><a href="url">link</a></p>
32```
33
34The URL can be split over multiple lines:
35
36```
37[link][]
38
39[link]:
40 url
41 andurl
42.
43<p><a href="urlandurl">link</a></p>
44```
45
46```
47[link](url
48andurl)
49.
50<p><a href="urlandurl">link</a></p>
51```
52
53```
54[link][]
55
56[link]:
57[link2]: url
58.
59<p><a href="">link</a></p>
60```
61
62```
63[link][]
64[link][link2]
65
66[link2]:
67 url2
68[link]:
69 url
70.
71<p><a href="url">link</a>
72<a href="url2">link</a></p>
73```
74
75```
76[link][a and
77b]
78
79[a and b]: url
80.
81<p><a href="url">link</a></p>
82```
83
84If the reference isn't found, we get an empty link.
85
86```
87[link][a and
88b]
89.
90<p><a>link</a></p>
91```
92
93Reference definitions can't have line breaks in the key:
94
95```
96[link][a and
97b]
98
99[a and
100b]: url
101.
102<p><a>link</a></p>
103<p>[a and
104b]: url</p>
105```
106
107No case normalization is done on reference definitions:
108
109```
110[Link][]
111
112[link]: /url
113.
114<p><a>Link</a></p>
115```
116
117Attributes on reference definitions get transferred to
118the link:
119
120```
121{title=foo}
122[ref]: /url
123
124[ref][]
125.
126<p><a href="/url" title="foo">ref</a></p>
127```
128
129Attributes on the link override those on references:
130
131```
132{title=foo}
133[ref]: /url
134
135[ref][]{title=bar}
136.
137<p><a href="/url" title="bar">ref</a></p>
138```
139
140```
141[link _and_ link][]
142
143[link and link]: url
144.
145<p><a href="url">link <em>and</em> link</a></p>
146```
147
148```
149![basic _image_](url)
150.
151<p><img alt="basic image" src="url"></p>
152```
153
154```
155[![image](img.jpg)](url)
156.
157<p><a href="url"><img alt="image" src="img.jpg"></a></p>
158```
159
160```
161[unclosed](hello *a
162b*
163.
164<p>[unclosed](hello <strong>a
165b</strong></p>
166```
167
168Note that soft breaks are ignored, so long URLs
169can be split over multiple lines:
170```
171[closed](hello *a
172b*)
173.
174<p><a href="hello *ab*">closed</a></p>
175```
176
177Here the strong takes precedence over the link because it
178starts first:
179```
180*[closed](hello*)
181.
182<p><strong>[closed](hello</strong>)</p>
183```
184
185Avoid this with a backslash escape:
186```
187*[closed](hello\*)
188.
189<p>*<a href="hello*">closed</a></p>
190```
191
192Link in link?
193```
194[[foo](bar)](baz)
195.
196<p><a href="baz"><a href="bar">foo</a></a></p>
197```
198
199Link in image?
200```
201![[link](url)](img)
202.
203<p><img alt="link" src="img"></p>
204```
205
206Image in link?
207```
208[![image](img)](url)
209.
210<p><a href="url"><img alt="image" src="img"></a></p>
211```
212
213Autolinks:
214```
215<http://example.com/foo>
216<me@example.com>
217.
218<p><a href="http://example.com/foo">http://example.com/foo</a>
219<a href="mailto:me@example.com">me@example.com</a></p>
220```
221
222Openers inside `[..](` or `[..][` or `[..]{` can't match
223outside them, even if the construction doesn't turn out to be
224a link or span or image.
225
226```
227[x_y](x_y)
228.
229<p><a href="x_y">x_y</a></p>
230```
231
232```
233[x_y](x_
234.
235<p>[x_y](x_</p>
236```
237
238```
239[x_y]{.bar_}
240.
241<p><span class="bar_">x_y</span></p>
242```