@@ -115,10 +115,245 @@ test('markdown -> mdast', function (t) {
115
115
'should support autolink literals'
116
116
)
117
117
118
+ t . deepEqual (
119
+ fromMarkdown (
120
+ `[http://localhost]: http://localhost "Open example on localhost"
121
+ [https://dev.local]: https://dev.local "Open example on localhost"
122
+
123
+ Existing link [http://localhost][], [https://dev.local][] in paragraph.` ,
124
+ {
125
+ extensions : [ syntax ] ,
126
+ mdastExtensions : [ autolinkLiterals . fromMarkdown ]
127
+ }
128
+ ) ,
129
+ {
130
+ type : 'root' ,
131
+ children : [
132
+ {
133
+ type : 'definition' ,
134
+ identifier : 'http://localhost' ,
135
+ label : 'http://localhost' ,
136
+ title : 'Open example on localhost' ,
137
+ url : 'http://localhost' ,
138
+ position : {
139
+ start : { line : 1 , column : 1 , offset : 0 } ,
140
+ end : { line : 1 , column : 65 , offset : 64 }
141
+ }
142
+ } ,
143
+ {
144
+ type : 'definition' ,
145
+ identifier : 'https://dev.local' ,
146
+ label : 'https://dev.local' ,
147
+ title : 'Open example on localhost' ,
148
+ url : 'https://dev.local' ,
149
+ position : {
150
+ start : { line : 2 , column : 1 , offset : 65 } ,
151
+ end : { line : 2 , column : 67 , offset : 131 }
152
+ }
153
+ } ,
154
+ {
155
+ type : 'paragraph' ,
156
+ children : [
157
+ {
158
+ type : 'text' ,
159
+ value : 'Existing link ' ,
160
+ position : {
161
+ start : { line : 4 , column : 1 , offset : 133 } ,
162
+ end : { line : 4 , column : 15 , offset : 147 }
163
+ }
164
+ } ,
165
+ {
166
+ type : 'linkReference' ,
167
+ children : [
168
+ {
169
+ type : 'text' ,
170
+ value : 'http://localhost' ,
171
+ position : {
172
+ start : { line : 4 , column : 16 , offset : 148 } ,
173
+ end : { line : 4 , column : 32 , offset : 164 }
174
+ }
175
+ }
176
+ ] ,
177
+ position : {
178
+ start : { line : 4 , column : 15 , offset : 147 } ,
179
+ end : { line : 4 , column : 35 , offset : 167 }
180
+ } ,
181
+ identifier : 'http://localhost' ,
182
+ label : 'http://localhost' ,
183
+ referenceType : 'collapsed'
184
+ } ,
185
+ {
186
+ type : 'text' ,
187
+ value : ', ' ,
188
+ position : {
189
+ start : { line : 4 , column : 35 , offset : 167 } ,
190
+ end : { line : 4 , column : 37 , offset : 169 }
191
+ }
192
+ } ,
193
+ {
194
+ type : 'linkReference' ,
195
+ children : [
196
+ {
197
+ type : 'text' ,
198
+ value : 'https://dev.local' ,
199
+ position : {
200
+ start : { line : 4 , column : 38 , offset : 170 } ,
201
+ end : { line : 4 , column : 55 , offset : 187 }
202
+ }
203
+ }
204
+ ] ,
205
+ position : {
206
+ start : { line : 4 , column : 37 , offset : 169 } ,
207
+ end : { line : 4 , column : 58 , offset : 190 }
208
+ } ,
209
+ identifier : 'https://dev.local' ,
210
+ label : 'https://dev.local' ,
211
+ referenceType : 'collapsed'
212
+ } ,
213
+ {
214
+ type : 'text' ,
215
+ value : ' in paragraph.' ,
216
+ position : {
217
+ start : { line : 4 , column : 58 , offset : 190 } ,
218
+ end : { line : 4 , column : 72 , offset : 204 }
219
+ }
220
+ }
221
+ ] ,
222
+ position : {
223
+ start : { line : 4 , column : 1 , offset : 133 } ,
224
+ end : { line : 4 , column : 72 , offset : 204 }
225
+ }
226
+ }
227
+ ] ,
228
+ position : {
229
+ start : { line : 1 , column : 1 , offset : 0 } ,
230
+ end : { line : 4 , column : 72 , offset : 204 }
231
+ }
232
+ } ,
233
+ 'should support existing link references with identifier as label'
234
+ )
235
+
118
236
t . end ( )
119
237
} )
120
238
121
239
test ( 'mdast -> markdown' , function ( t ) {
240
+ t . deepEqual (
241
+ toMarkdown (
242
+ {
243
+ type : 'root' ,
244
+ children : [
245
+ {
246
+ type : 'definition' ,
247
+ identifier : 'http://localhost' ,
248
+ label : 'http://localhost' ,
249
+ title : 'Open example on localhost' ,
250
+ url : 'http://localhost' ,
251
+ position : {
252
+ start : { line : 1 , column : 1 , offset : 0 } ,
253
+ end : { line : 1 , column : 65 , offset : 64 }
254
+ }
255
+ } ,
256
+ {
257
+ type : 'definition' ,
258
+ identifier : 'https://dev.local' ,
259
+ label : 'https://dev.local' ,
260
+ title : 'Open example on localhost' ,
261
+ url : 'https://dev.local' ,
262
+ position : {
263
+ start : { line : 2 , column : 1 , offset : 65 } ,
264
+ end : { line : 2 , column : 67 , offset : 131 }
265
+ }
266
+ } ,
267
+ {
268
+ type : 'paragraph' ,
269
+ children : [
270
+ {
271
+ type : 'text' ,
272
+ value : 'Existing link ' ,
273
+ position : {
274
+ start : { line : 4 , column : 1 , offset : 133 } ,
275
+ end : { line : 4 , column : 15 , offset : 147 }
276
+ }
277
+ } ,
278
+ {
279
+ type : 'linkReference' ,
280
+ children : [
281
+ {
282
+ type : 'text' ,
283
+ value : 'http://localhost' ,
284
+ position : {
285
+ start : { line : 4 , column : 16 , offset : 148 } ,
286
+ end : { line : 4 , column : 32 , offset : 164 }
287
+ }
288
+ }
289
+ ] ,
290
+ position : {
291
+ start : { line : 4 , column : 15 , offset : 147 } ,
292
+ end : { line : 4 , column : 35 , offset : 167 }
293
+ } ,
294
+ identifier : 'http://localhost' ,
295
+ label : 'http://localhost' ,
296
+ referenceType : 'collapsed'
297
+ } ,
298
+ {
299
+ type : 'text' ,
300
+ value : ', ' ,
301
+ position : {
302
+ start : { line : 4 , column : 35 , offset : 167 } ,
303
+ end : { line : 4 , column : 37 , offset : 169 }
304
+ }
305
+ } ,
306
+ {
307
+ type : 'linkReference' ,
308
+ children : [
309
+ {
310
+ type : 'text' ,
311
+ value : 'https://dev.local' ,
312
+ position : {
313
+ start : { line : 4 , column : 38 , offset : 170 } ,
314
+ end : { line : 4 , column : 55 , offset : 187 }
315
+ }
316
+ }
317
+ ] ,
318
+ position : {
319
+ start : { line : 4 , column : 37 , offset : 169 } ,
320
+ end : { line : 4 , column : 58 , offset : 190 }
321
+ } ,
322
+ identifier : 'https://dev.local' ,
323
+ label : 'https://dev.local' ,
324
+ referenceType : 'collapsed'
325
+ } ,
326
+ {
327
+ type : 'text' ,
328
+ value : ' in paragraph.' ,
329
+ position : {
330
+ start : { line : 4 , column : 58 , offset : 190 } ,
331
+ end : { line : 4 , column : 72 , offset : 204 }
332
+ }
333
+ }
334
+ ] ,
335
+ position : {
336
+ start : { line : 4 , column : 1 , offset : 133 } ,
337
+ end : { line : 4 , column : 72 , offset : 204 }
338
+ }
339
+ }
340
+ ] ,
341
+ position : {
342
+ start : { line : 1 , column : 1 , offset : 0 } ,
343
+ end : { line : 4 , column : 72 , offset : 204 }
344
+ }
345
+ } ,
346
+ { extensions : [ autolinkLiterals . toMarkdown ] }
347
+ ) ,
348
+ `[http://localhost]: http://localhost "Open example on localhost"
349
+
350
+ [https://dev.local]: https://dev.local "Open example on localhost"
351
+
352
+ Existing link [http://localhost][], [https://dev.local][] in paragraph.
353
+ ` ,
354
+ 'should not escape existing link text.'
355
+ )
356
+
122
357
t . deepEqual (
123
358
toMarkdown (
124
359
{
0 commit comments