#outline()
= #link("https://example.com")[Link in Heading] <heading>
This is the most intuitive approach, but unfortunately it does not meet 1. There’re two nested <a> in #outline, and clicking it will go to the inner one.
<nav role="doc-toc">
<h2>Contents</h2>
<ol style="list-style-type: none">
<li><a href="#heading"><a href="https://example.com">Link in Heading</a></a></li>
</ol>
</nav>
<h2 id="heading"><a href="https://example.com">Link in Heading</a></h2>
Heading in Link
#outline()
#link("https://example.com")[#[= Heading in Link] <heading>]
This satisfies 1 and 2, but not 3, because <h2> is wrapped in a <p>.
<nav role="doc-toc">
<h2>Contents</h2>
<ol style="list-style-type: none">
<li><a href="#heading">Heading in Link</a></li>
</ol>
</nav>
<p><a href="https://example.com"><h2 id="heading">Heading in Link</h2></a></p>
In my browser (Firefox 147), the invalid HTML results in an empty <a> and two additional <p>s.
In my case, I find that hacking links in #outline is more practical.
#show outline: body => {
show link: it => if type(it.dest) == str {
// Remove external links
it.body
} else {
it
}
body
}
#outline()
= #link("https://example.com")[Link in Heading] <heading>
<nav role="doc-toc">
<h2>Contents</h2>
<ol style="list-style-type: none">
<li><a href="#heading">Heading in Link</a></li>
</ol>
</nav>
<h2 id="heading"><a href="https://example.com">Link in Heading</a></h2>
I think the 2 current native ways pretty much do what you tell it, therefore this external link use case needs something else. So a feature request to support this kind of setup natively, because you can’t do that without hacking.
Doesn’t seem that hacky to me. It expresses what you want: No external links in the outline. Semantically it’s not perfect, but with a replacing selector it would be fine.
Regarding opening an issue: The current behavior seems correct to me. And I don’t really see what to add to the language here. The show rule you wrote uses existing composable mechanism to do precisely what you want.
I think it’s hacky because it’s a show-function rule. I won’t be able to revert it without introducing extra complexity. For example, the outline might link to an appendix that lives in another html page.
Well, to some extent, I agree as well.
In the example below, link (Antigravity) is only a part of the heading. Perhaps the link should be kept in outline. If so, then it will be quite confusing that deleting The Essense of would cause the link to disappear…
= The Essence of #link("https://example.com")[Antigravity]