@@ -222,84 +222,80 @@ def test_reference_with_markup() -> None:
222
222
223
223
def test_legacy_custom_required_reference () -> None :
224
224
"""Check that external HTML-based references are expanded or reported missing."""
225
- url_map = {"ok" : "ok.html#ok" }
226
- source = "<span data-autorefs-identifier=bar>foo</span> <span data-autorefs-identifier=ok>ok</span>"
227
225
with pytest .warns (DeprecationWarning , match = "`span` elements are deprecated" ):
228
- output , unmapped = fix_refs (source , url_map .__getitem__ )
229
- assert output == '[foo][bar] <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a>'
230
- assert unmapped == [("bar" , None )]
226
+ run_references_test (
227
+ url_map = {"ok" : "ok.html#ok" },
228
+ source = "<span data-autorefs-identifier=bar>foo</span> <span data-autorefs-identifier=ok>ok</span>" ,
229
+ output = '<p>[foo][bar] <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a></p>' ,
230
+ unmapped = [("bar" , None )],
231
+ )
231
232
232
233
233
234
def test_custom_required_reference () -> None :
234
235
"""Check that external HTML-based references are expanded or reported missing."""
235
- url_map = {"ok" : "ok.html#ok" }
236
- source = "<autoref identifier=bar>foo</autoref> <autoref identifier=ok>ok</autoref>"
237
- output , unmapped = fix_refs (source , url_map .__getitem__ )
238
- assert output == '[foo][bar] <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a>'
239
- assert unmapped == [("bar" , None )]
236
+ run_references_test (
237
+ url_map = {"ok" : "ok.html#ok" },
238
+ source = "<autoref identifier=bar>foo</autoref> <autoref identifier=ok>ok</autoref>" ,
239
+ output = '<p>[foo][bar] <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a></p>' ,
240
+ unmapped = [("bar" , None )],
241
+ )
240
242
241
243
242
244
def test_legacy_custom_optional_reference () -> None :
243
245
"""Check that optional HTML-based references are expanded and never reported missing."""
244
- url_map = {"ok" : "ok.html#ok" }
245
- source = '<span data-autorefs-optional="bar">foo</span> <span data-autorefs-optional=ok>ok</span>'
246
246
with pytest .warns (DeprecationWarning , match = "`span` elements are deprecated" ):
247
- output , unmapped = fix_refs (source , url_map .__getitem__ )
248
- assert output == 'foo <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a>'
249
- assert unmapped == []
247
+ run_references_test (
248
+ url_map = {"ok" : "ok.html#ok" },
249
+ source = '<span data-autorefs-optional="bar">foo</span> <span data-autorefs-optional=ok>ok</span>' ,
250
+ output = '<p>foo <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a></p>' ,
251
+ )
250
252
251
253
252
254
def test_custom_optional_reference () -> None :
253
255
"""Check that optional HTML-based references are expanded and never reported missing."""
254
- url_map = { "ok" : "ok.html#ok" }
255
- source = '<autoref optional identifier="bar">foo</autoref> <autoref identifier=ok optional>ok</autoref>'
256
- output , unmapped = fix_refs ( source , url_map . __getitem__ )
257
- assert output == ' foo <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a>'
258
- assert unmapped == []
256
+ run_references_test (
257
+ url_map = { "ok" : "ok.html#ok" },
258
+ source = '<autoref optional identifier="bar">foo</autoref> <autoref identifier=ok optional>ok</autoref>' ,
259
+ output = '<p> foo <a class="autorefs autorefs-internal" href="ok.html#ok">ok</a></p>' ,
260
+ )
259
261
260
262
261
263
def test_legacy_custom_optional_hover_reference () -> None :
262
264
"""Check that optional-hover HTML-based references are expanded and never reported missing."""
263
- url_map = {"ok" : "ok.html#ok" }
264
- source = '<span data-autorefs-optional-hover="bar">foo</span> <span data-autorefs-optional-hover=ok>ok</span>'
265
265
with pytest .warns (DeprecationWarning , match = "`span` elements are deprecated" ):
266
- output , unmapped = fix_refs (source , url_map .__getitem__ )
267
- assert (
268
- output
269
- == '<span title="bar">foo</span> <a class="autorefs autorefs-internal" title="ok" href="ok.html#ok">ok</a>'
270
- )
271
- assert unmapped == []
266
+ run_references_test (
267
+ url_map = {"ok" : "ok.html#ok" },
268
+ source = '<span data-autorefs-optional-hover="bar">foo</span> <span data-autorefs-optional-hover=ok>ok</span>' ,
269
+ output = '<p><span title="bar">foo</span> <a class="autorefs autorefs-internal" title="ok" href="ok.html#ok">ok</a></p>' ,
270
+ )
272
271
273
272
274
273
def test_custom_optional_hover_reference () -> None :
275
274
"""Check that optional-hover HTML-based references are expanded and never reported missing."""
276
- url_map = {"ok" : "ok.html#ok" }
277
- source = '<autoref optional hover identifier="bar">foo</autoref> <autoref optional identifier=ok hover>ok</autoref>'
278
- output , unmapped = fix_refs (source , url_map .__getitem__ )
279
- assert (
280
- output
281
- == '<span title="bar">foo</span> <a class="autorefs autorefs-internal" title="ok" href="ok.html#ok">ok</a>'
275
+ run_references_test (
276
+ url_map = {"ok" : "ok.html#ok" },
277
+ source = '<autoref optional hover identifier="bar">foo</autoref> <autoref optional identifier=ok hover>ok</autoref>' ,
278
+ output = '<p><span title="bar">foo</span> <a class="autorefs autorefs-internal" title="ok" href="ok.html#ok">ok</a></p>' ,
282
279
)
283
- assert unmapped == []
284
280
285
281
286
282
def test_legacy_external_references () -> None :
287
283
"""Check that external references are marked as such."""
288
- url_map = {"example" : "https://example.com" }
289
- source = '<span data-autorefs-optional="example">example</span>'
290
284
with pytest .warns (DeprecationWarning , match = "`span` elements are deprecated" ):
291
- output , unmapped = fix_refs (source , url_map .__getitem__ )
292
- assert output == '<a class="autorefs autorefs-external" href="https://example.com">example</a>'
293
- assert unmapped == []
285
+ run_references_test (
286
+ url_map = {"example" : "https://example.com/#example" },
287
+ source = '<span data-autorefs-optional="example">example</span>' ,
288
+ output = '<p><a class="autorefs autorefs-external" href="https://example.com/#example">example</a></p>' ,
289
+ )
294
290
295
291
296
292
def test_external_references () -> None :
297
293
"""Check that external references are marked as such."""
298
- url_map = { "example" : "https://example.com" }
299
- source = '<autoref optional identifier= "example"> example</autoref>'
300
- output , unmapped = fix_refs ( source , url_map . __getitem__ )
301
- assert output == '< a class="autorefs autorefs-external" href="https://example.com">example</a>'
302
- assert unmapped == []
294
+ run_references_test (
295
+ url_map = { "example" : "https:// example.com/#example" },
296
+ source = '<autoref optional identifier="example">example</autoref>' ,
297
+ output = '<p>< a class="autorefs autorefs-external" href="https://example.com/#example ">example</a></p>' ,
298
+ )
303
299
304
300
305
301
def test_register_markdown_anchors () -> None :
@@ -392,19 +388,21 @@ def test_register_markdown_anchors_with_admonition() -> None:
392
388
393
389
def test_legacy_keep_data_attributes () -> None :
394
390
"""Keep HTML data attributes from autorefs spans."""
395
- url_map = {"example" : "https://e.com" }
396
- source = '<span data-autorefs-optional="example" class="hi ho" data-foo data-bar="0">e</span>'
397
391
with pytest .warns (DeprecationWarning , match = "`span` elements are deprecated" ):
398
- output , _ = fix_refs (source , url_map .__getitem__ )
399
- assert output == '<a class="autorefs autorefs-external hi ho" href="https://e.com" data-foo data-bar="0">e</a>'
392
+ run_references_test (
393
+ url_map = {"example" : "https://e.com/#example" },
394
+ source = '<span data-autorefs-optional="example" class="hi ho" data-foo data-bar="0">e</span>' ,
395
+ output = '<p><a class="autorefs autorefs-external hi ho" href="https://e.com/#example" data-foo data-bar="0">e</a></p>' ,
396
+ )
400
397
401
398
402
399
def test_keep_data_attributes () -> None :
403
400
"""Keep HTML data attributes from autorefs spans."""
404
- url_map = {"example" : "https://e.com" }
405
- source = '<autoref optional identifier="example" class="hi ho" data-foo data-bar="0">e</autoref>'
406
- output , _ = fix_refs (source , url_map .__getitem__ )
407
- assert output == '<a class="autorefs autorefs-external hi ho" href="https://e.com" data-foo data-bar="0">e</a>'
401
+ run_references_test (
402
+ url_map = {"example" : "https://e.com#a" },
403
+ source = '<autoref optional identifier="example" class="hi ho" data-foo data-bar="0">e</autoref>' ,
404
+ output = '<p><a class="autorefs autorefs-external hi ho" href="https://e.com#a" data-foo data-bar="0">e</a></p>' ,
405
+ )
408
406
409
407
410
408
@pytest .mark .parametrize (
0 commit comments