Skip to content

relfileprefix on multipage pages blocks doc-comment links to non-reference pages #1245

Description

@jll63

Summary

:relfileprefix:, set by adoc/layouts/wrapper.adoc.hbs on every multipage symbol page, makes it impossible for a doc comment on a nested symbol to link to a page outside the generated reference. Under Antora that means a reference page cannot link back to a hand-written guide page, so the cross-reference between narrative docs and reference is one-directional.

Background

A doc comment can reach a non-symbol page by giving a markdown link an Antora resource ID as its target — markup/a.adoc.hbs emits a scheme-ful href verbatim, so the ID survives:

/// @see [Shared Libraries](xref:ROOT:shared_libraries.adoc)
#define MY_MACRO(x) /* ... */

xref:ROOT:shared_libraries.adoc[Shared Libraries]

This works on pages at the output root. It fails on every nested page.

Cause

wrapper.adoc.hbs emits

:relfileprefix: {{{ page.relfileprefix }}}

with the comment "As Antora does not support relative links to pages in parent directories, the relfileprefix attribute is set to make all links relative to the root directory."

Asciidoctor folds relfileprefix into the path attribute of an inter-document xref, and Antora's converter uses exactly that attribute as the resource ID to resolve (asciidoc-loader/lib/converter/html5.js: let refSpec = node.getAttribute('path')). So a module-qualified ID is corrupted:

xref:ROOT:error_handling.adoc  ->  ../../ROOT:error_handling.adoc  ->  target of xref not found

A leading ../../ can never be part of a valid resource ID, so no spelling of the link survives.

Why the attribute cannot simply be dropped

Clearing it (relfileprefix: '', locked from the Antora playbook) does fix those links, and MrDocs' own body xrefs keep resolving — Antora resolves xref:boost/openmethod/foo.adoc family-root-relative, no prefix needed. But it breaks the document title:

= xref:boost.adoc[boost]::xref:boost/openmethod.adoc[openmethod]::ambiguous_call

Title xrefs are not processed by Antora's converter — they are converted by plain Asciidoctor, which does need relfileprefix to produce a usable relative path. On a real project (Boost.OpenMethod, ~200 nested reference pages) I measured:

configuration broken internal links
relfileprefix as MrDocs sets it the guide links only
relfileprefix cleared ~1250 (h1 + breadcrumb on every nested page)

So the attribute is load-bearing for exactly one thing: the title.

Suggested fix

Have symbol/qualified-name-title build its parent links with page.relfileprefix applied to the href directly, and stop emitting the document attribute. The title then works under plain Asciidoctor as it does today, Antora resolves body xrefs on its own, and a module-qualified resource ID in a doc comment survives — making reference → guide links possible from any page.

A lighter variant, if inlining the prefix in the title is awkward: render the parent names as plain text and drop the attribute. That loses the clickable breadcrumb.

Environment

MrDocs 0.8.0+e37b111 and current develop, generate: adoc, multipage: true, consumed by Antora 3.1.14 via @cppalliance/antora-cpp-reference-extension.

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