HTML link tests

This commit is contained in:
Laurenz 2025-07-15 10:45:39 +02:00
parent 83ee0c0e73
commit 63bc1e9fe2
6 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<p id="loc-1"><a href="#loc-1">Go</a></p>
</body>
</html>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<ul>
<li><a href="#t1">Go</a></li>
<li><a href="#t2">Go</a></li>
<li><a href="#t3">Go</a></li>
<li><a href="#t4">Go</a></li>
<li><a href="#t5">Go</a></li>
<li><a href="#t6">Go</a></li>
<li><a href="#t7">Go</a></li>
<li><a href="#t8">Go</a></li>
</ul>
<p id="t1">Hi</p>
<p id="t2">Hi there</p>
<p>See <span id="t4">it</span></p>
<p>See <span id="t5">it</span> here</p>
<p>See <span id="t6">a</span> <strong>b</strong></p>
<p>See <strong id="t3">a <em>b</em></strong></p>
<p>See</p>
<span id="t7"></span>
<p>See</p>
<span id="t8"></span>
</body>
</html>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div><span id="this">This</span></div>
<p><a href="#this">Go</a></p>
</body>
</html>

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2 id="loc-1">A</h2>
<h2 id="loc-3">B</h2>
<h2 id="loc">C</h2>
<h2 id="loc-2">D</h2>
<h2 id="lib-1">E</h2>
<h2 id="lib-3">F</h2>
<h2 id="lib-2">G</h2>
<h2 id="hi">H</h2>
<h2 id="hi-2-1">I</h2>
<h2 id="hi-2-2">J</h2>
<ul>
<li><a href="#loc-1">A</a></li>
<li><a href="#loc-3">B</a></li>
<li><a href="#loc">C</a></li>
<li><a href="#loc-2">D</a></li>
<li><a href="#lib-1">E</a></li>
<li><a href="#lib-3">F</a></li>
<li><a href="#lib-2">G</a></li>
<li><a href="#hi">H</a></li>
<li><a href="#hi-2-1">I</a></li>
<li><a href="#hi-2-2">J</a></li>
</ul>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<span id="a"></span><span id="b"></span>
<p>Hi</p>
<p><a href="#a">A</a> <a href="#b">B</a> <a href="#a">C</a></p>
</body>
</html>

View File

@ -66,6 +66,74 @@ My cool #box(move(dx: 0.7cm, dy: 0.7cm, rotate(10deg, scale(200%, mylink))))
Text <hey> Text <hey>
#link(<hey>)[Go to text.] #link(<hey>)[Go to text.]
--- link-html-id-attach html ---
// Tests how IDs and, if necessary, spans, are added to the DOM to support
// links.
#for i in range(1, 9) {
list.item(link(label("t" + str(i)), [Go]))
}
// Text at start of paragraph
Hi <t1>
// Text at start of paragraph + more text
Hi <t2> there
// Text in the middle of paragraph
See #[it <t4>]
// Text in the middle of paragraph + more text
See #[it <t5>] here
// Text + more elements
See #[a *b*] <t6>
// Element
See *a _b_* <t3>
// Nothing
See #[] <t7>
// Nothing 2
See #metadata(none) <t8>
--- link-html-label-disambiguation html ---
// Tests automatic ID generation for labelled elements.
#[= A] #label("%") // not reusable => loc-1
= B <1> // not reusable => loc-3 (loc-2 exists)
= C <loc> // reusable, unique => loc
= D <loc-2> // reusable, unique => loc-2
= E <lib> // reusable, not unique => lib-1
= F <lib> // reusable, not unique => lib-3 (lib-2 exists)
= G <lib-2> // reusable, unique => lib-2
= H <hi> // reusable, unique => hi
= I <hi-2> // reusable, not unique => hi-2-1
= J <hi-2> // reusable, not unique => hi-2-2
#context for it in query(heading) {
list.item(link(it.location(), it.body))
}
--- link-html-id-existing html ---
// Test that linking reuses the existing ID, if any.
#html.div[
#html.span(id: "this")[This] <other>
]
#link(<other>)[Go]
--- link-html-here html ---
#context link(here())[Go]
--- link-html-nested-empty html ---
#[#metadata(none) <a> #metadata(none) <b> Hi] <c>
#link(<a>)[A] // creates empty span
#link(<b>)[B] // creates second empty span
#link(<c>)[C] // links to #a because the generated span is contained in it
--- link-to-label-missing --- --- link-to-label-missing ---
// Error: 2-20 label `<hey>` does not exist in the document // Error: 2-20 label `<hey>` does not exist in the document
#link(<hey>)[Nope.] #link(<hey>)[Nope.]