Skip to content

BUG: Relative URLs broken by <base> tag in multi-page HTML output #834

Description

@NicolasRouquette

Summary

In multi-page HTML output, the use of the <base> tag currently shifts URL resolution in a way that breaks two distinct types of resources: user-authored relative images and system-injected KaTeX assets.

This issue aims to clarify the expected behavior for these links and document where the current multi-page output diverges from that expectation.

Expected Behavior (Proposed Link Resolution Rules)

To ensure a predictable experience for Verso authors, links and assets should conceptually resolve as follows:

  1. User-authored relative paths: If an author includes a relative link or image in a Markdown file (e.g., ![diagram](graphs/foo.svg)), that path should resolve relative to the location of that specific page within the project structure.
  2. System-injected internal assets: Internal Verso assets (like KaTeX scripts mapped to /-verso-data/katex/...) should reliably resolve to the generated site-root directory, regardless of how deeply nested the current page is.

Reproduction

Setup:

  • Verso v4.29.0, multi-page HTML output enabled.
  • KaTeX feature enabled.
  • A nested page created at the path: Verification/Key-Theorems/
  • The Markdown content for that page includes a local image reference: ![diagram](graphs/foo.svg)

Actual Behavior

Because the generator injects <base href="./../../"> on the nested page, it alters the base URL for the entire document, breaking both rules defined above:

1. Markdown Images (Overshoots local directory)
The relative image ![diagram](graphs/foo.svg) is rendered in the HTML as <img src="graphs/foo.svg">.
Because of the <base> tag, the browser resolves this from the site root rather than the page directory.

  • Expected: {site-root}/Verification/Key-Theorems/graphs/foo.svg
  • Actual: {site-root}/graphs/foo.svg (404)

2. KaTeX Assets (Overshoots site root)
Absolute internal assets like /-verso-data/katex/katex.js are currently relativized by the compiler to ../../-verso-data/katex/katex.js.
Because the <base> tag already navigates the browser back to the site root, the additional ../../ prefix causes the browser to overshoot the root entirely.

  • Expected: {site-root}/-verso-data/katex/katex.js
  • Actual: {two-levels-above-site-root}/-verso-data/katex/katex.js (404)

Browser console output shows:
GET https://example.com/pages/-verso-data/katex/katex.js net::ERR_ABORTED 404

Proposed Fix

I have identified the root causes for both of these URL resolution issues in Html.lean and VersoManual.lean and opened a PR with a proposed fix here: #835

The PR adjusts the compiler to ensure user-authored relative paths are prefixed with their page path before the <base> tag shifts resolution, and prevents absolute asset URLs from generating redundant ../ sequences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions