Skip to content

Cross-page anchor links from toctree (maxdepth > 1) don't resolve anchor on Confluence Cloud #1178

@jhaase1

Description

@jhaase1

Summary

When using maxdepth: 2 in toctrees, the builder generates cross-page section links using ac:link ac:anchorac:structured-macro ac:name="anchor". The storage format is correct on both source and target pages. However, on Confluence Cloud (v2/fabric editor), clicking these links navigates to the correct page but drops the anchor fragment — the browser does not scroll to the referenced section.

Environment

  • sphinxcontrib-confluencebuilder: 3.0.0
  • Sphinx: 9.0.4
  • Python: 3.11.9
  • Confluence: Cloud (.[atlassian.net/wiki/](http://atlassian.net/wiki/))
  • Editor: v2 (auto-detected by builder v3.0)
  • API mode: v2 (auto-detected)
  • No explicit confluence_editor or confluence_api_mode set

Reproduction

Source document (guide/index.md)

## User Guide Pages

```{toctree}
:maxdepth: 2

models-to-focus

### Target document (`guide/models-to-focus.md`)

```markdown
# Models to Focus

Some intro text.

## Data Source

Models to Focus queries the `trigger_programs_of_concern` table...

## Key Metrics

### Score

A composite battery health score...

Build command

sphinx-build -M confluence docs docs/_build -E -a

Generated storage format

Source page (guide/index) — toctree links

<ac:link ac:anchor="Data-Source">
<ri:page ri:content-title="Models to Focus" />
<ac:link-body>Data Source</ac:link-body>
</ac:link>

Target page (guide/models-to-focus) — anchor definitions

<h2><ac:structured-macro ac:name="anchor">
<ac:parameter ac:name="">Data-Source</ac:parameter>
</ac:structured-macro><ac:structured-macro ac:name="anchor">
<ac:parameter ac:name="">ModelstoFocus-Data-Source</ac:parameter>
</ac:structured-macro>Data Source</h2>

Both sides match: ac:link ac:anchor="Data-Source" references ac:structured-macro ac:name="anchor" with parameter Data-Source.

Observed behavior

Clicking the "Data Source" link in the toctree navigates to:

https://example.atlassian.net/wiki/spaces/MYSPACE/pages/123456

The anchor fragment (#Data-Source) is not appended; the page loads at the top.

Expected behavior

The link should navigate to:

https://example.atlassian.net/wiki/spaces/MYSPACE/pages/123456/Models+to+Focus#Data-Source

...scrolling to the "Data Source" heading.

Additional context

  • Confluence Cloud's v2 editor wraps anchor macros as inline extensions. Inspecting the rendered DOM, the heading's HTML id attribute becomes [inlineExtension][inlineExtension]Data-Source (because the two ac:structured-macro elements inside the <h2> are serialized as [inlineExtension] tokens). The ac:link ac:anchor="Data-Source" may fail to resolve because the rendered anchor ID doesn't match Data-Source.
  • Same-page TOC links work. The Confluence-native TOC macro generates URLs with the [inlineExtension] prefix and correctly scrolls to sections.
  • Using maxdepth: 1 avoids the issue (no sub-section anchor links generated), but loses section-level detail in navigation.
  • Not the same as Link to section titles - broken ? #1057 (Data Center v2 anchor formatting, fixed v2.9). Our anchors have no special characters — simple slugs like Data-Source, Purpose, Key-Metrics.
  • PR Replace special anchor handling #1129 ("Replace special anchor handling") targets anchors with characters like parentheses and is included in v3.0.0, but does not apply to our simple anchor names.
  • A contributor in sphinxcontrib-confluencebuilder v3 Cloud Users Notice #1166 reported a similar symptom ("anchors link to page but not section") which allegedly resolved after republishing. We have republished multiple times (including with CONFLUENCE_CLOUD_V2_MIGRATION=1) and the issue persists.

Workaround

Set maxdepth: 1 on all toctrees to avoid generating cross-page section links. This prevents broken links but loses section-level navigation from parent pages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    available-next-releaseMerged into the main branch but waiting for PyPI releaseconfluence-issueAn issue that related to a Confluence-related bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions