@@ -222,84 +222,80 @@ def test_reference_with_markup() -> None:
222222
223223def test_legacy_custom_required_reference () -> None :
224224 """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>"
227225 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+ )
231232
232233
233234def test_custom_required_reference () -> None :
234235 """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+ )
240242
241243
242244def test_legacy_custom_optional_reference () -> None :
243245 """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>'
246246 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+ )
250252
251253
252254def test_custom_optional_reference () -> None :
253255 """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+ )
259261
260262
261263def test_legacy_custom_optional_hover_reference () -> None :
262264 """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>'
265265 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+ )
272271
273272
274273def test_custom_optional_hover_reference () -> None :
275274 """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>' ,
282279 )
283- assert unmapped == []
284280
285281
286282def test_legacy_external_references () -> None :
287283 """Check that external references are marked as such."""
288- url_map = {"example" : "https://example.com" }
289- source = '<span data-autorefs-optional="example">example</span>'
290284 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+ )
294290
295291
296292def test_external_references () -> None :
297293 """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+ )
303299
304300
305301def test_register_markdown_anchors () -> None :
@@ -392,19 +388,21 @@ def test_register_markdown_anchors_with_admonition() -> None:
392388
393389def test_legacy_keep_data_attributes () -> None :
394390 """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>'
397391 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+ )
400397
401398
402399def test_keep_data_attributes () -> None :
403400 """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+ )
408406
409407
410408@pytest .mark .parametrize (
0 commit comments