Skip to content

HTML: Internal links only using anchors, not filename, for portable builds #2566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

oscarlevin
Copy link
Member

In a portable build, it is reasonable to want to rename the single html file that results (for sending to admin in case you are building a syllabus, for example). For this to work, internal URLs need to only contain the anchor tag, not the filename. This PR inserts a test for not being a portable build before the "containing filename" is inserted as part of the url.

@rbeezer
Copy link
Collaborator

rbeezer commented Jun 29, 2025

I see three empty HTML @href in output for sample article. ToC for Front Matter (maybe not really observable in use), ToC for Reference (makes ToC inoperable for that division), and there is a test xref to the "root" of the document, which is translated to the title page or front matter or something. Search the source for main title page to locate that and see what's up there.

Not immediately obvious to me how or why these slip through.

I might expand the code comment some when the time comes - you don't need to be concerned with that as this gets revised.

@oscarlevin
Copy link
Member Author

Interesting. This has revealed a previous bug with chunking level=0 I think, rather than it being an issue with this PR. If you build the sample article with portable="yes" or just chunking level="0" on the master branch, you will get the much worse error that the link to References in the TOC is to the html file "backmatter.html" which doesn't exist. The other two instances really should be blank hrefs (or they could be href="#", which would be a little better I guess) since they should go to the top of the page (a blank href will just reload the page).

I'll split this fix into a second commit here, and try to make the current commit slightly more robust (so that jumping to the top of the page is an anchor and not a page reload).

@oscarlevin
Copy link
Member Author

oscarlevin commented Jun 29, 2025

Okay, I fixed both issues with a single commit. It makes more changes to the xsl (splitting out a modal url-anchor template, but I think the logic is better. Tests on $chunk-level = 0 rather than $b-is-portable so this also fixes the aforementioned bug (which also applied to frontmatter, it turned out).

@rbeezer
Copy link
Collaborator

rbeezer commented Jul 1, 2025

I like how this became better as it became more general!

An "anchor" is the target and the pointer (with #) is a "fragment identifier'.

So I made some cosmetic edits to switch "anchor" into "fragment". No changes to the code - nicely done.

@rbeezer rbeezer closed this Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants