A section link names the TEXT of a heading: :section alone means the current file, a value names the file of the same @document that has it. Resolved by @document at assembly in html and tex; errors for a missing file, a missing title, a doubled title and a link outside a @document. The Markdown converter reads a Markdown anchor as a section link to the heading its slug names. Also from dev: the converter's four silent defects fixed and --chapter (9ae2c4cd), and the engine's alone-value error text. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
25 lines
1.0 KiB
JavaScript
25 lines
1.0 KiB
JavaScript
|
|
// In-text links to a section on another (or the same) page of a book:
|
|
// <a class="pagelink" data-page="BASENAME" data-id="ID">, which @document
|
|
// emits for @link ... :section @ (document_html.cpp, resolve_section_links).
|
|
// go_to_section() swaps in the embedded page and scrolls to the id, and
|
|
// calls this again for the links of the page it just showed. Each anchor
|
|
// is bound once: a page shown twice is the same nodes bound twice otherwise.
|
|
function set_link_listeners() {
|
|
Array.from(document.getElementsByClassName("pagelink")).forEach(
|
|
function (elt) {
|
|
if (elt.getAttribute("data-bound")) {
|
|
return;
|
|
}
|
|
elt.setAttribute("data-bound", "true");
|
|
elt.addEventListener("click", function(event) {
|
|
event.preventDefault();
|
|
let basename = elt.getAttribute("data-page");
|
|
let id = elt.getAttribute("data-id");
|
|
go_to_section(elt, basename, id);
|
|
});
|
|
});
|
|
}
|
|
|
|
window.addEventListener("load", set_link_listeners);
|