Skip to content

AsciiDoc renderer does not render BlockId anchors

Summary

When rendering AsciiDoc on GitLab, user-defined anchors are dropped which breaks the table of contents.

Steps to reproduce

Put an AsciiDoc BlockId anchor like [[example_anchor]] in the text.

Example Project

https://gitlab.com/jyutzler/asciidoc-test/blob/master/bug1.adoc

What is the current bug behavior?

  1. In the rendered HTML, no id attribute is added to the HTML <p> element that the anchor refers to. Therefore attempts to click on a cross-reference fail.
  2. If the anchor is added before a section header, the system-generated id is removed from the corresponding <div> which breaks the Table of Contents. The Table of Contents has the correct cross-reference name, but the browser has no anchor to go to.

What is the expected correct behavior?

  1. When an anchor is present, a corresponding id attribute is added to the HTML element directly after the anchor.
  2. When the anchor is for a section header, the system-generated id is replaced with the name of the anchor.

Relevant logs and/or screenshots

This

:doctype: book
:encoding: utf-8
:lang: en
:toc: macro
:toclevels: 3
:numbered:
:sectanchors:

toc::[]

## Introduction
1. What if we want to go to an <<anchor,anchor>>? 
2. What if the anchor is in <<another_section>>?

## Next Section
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

[[anchor]]
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

[[another_section]]
## Another Section
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

generates:

<div class="file-content md md-file">
<div>
<div>
<div>
<div>Table of Contents</div>
<ul>
<li><a href="#user-content-introduction">1. Introduction</a></li>
<li><a href="#user-content-next-section">2. Next Section</a></li>
<li><a href="#another_section">3. Another Section</a></li>
</ul>
</div>
</div>
</div>
<div>
<h2 id="user-content-introduction">
<a class="anchor" href="#user-content-introduction"></a>1. Introduction</h2>
<div>
<div>
<ol>
<li>
<p>What if we want to go to an <a href="#anchor">anchor</a>?</p>
</li>
<li>
<p>What if the anchor is in <a href="#another_section">Another Section</a>?</p>
</li>
</ol>
</div>
</div>
</div>
<div>
<h2 id="user-content-next-section">
<a class="anchor" href="#user-content-next-section"></a>2. Next Section</h2>
<div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
<div>
<h2>
<a class="anchor" href="#another_section"></a>3. Another Section</h2>
<div>
<div>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
</div>
<div>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
</div>

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖