Commit 37a23018 authored by Michael Hamann's avatar Michael Hamann
Browse files

XRENDERING-620: Overridden heading ids are not taken into account by the ToC Macro

* Prefer the manually set heading id over the generated one.
* Add a test case.
parent 22eac2b1
......@@ -189,7 +189,12 @@ private ListItemBlock createTocEntry(HeaderBlock headerBlock, String documentRef
{
// Create the link to target the header anchor
DocumentResourceReference reference = new DocumentResourceReference(documentReference);
reference.setAnchor(headerBlock.getId());
String idParameter = headerBlock.getParameter("id");
if (idParameter != null) {
reference.setAnchor(idParameter);
} else {
reference.setAnchor(headerBlock.getId());
}
LinkBlock linkBlock = new LinkBlock(this.tocBlockFilter.generateLabel(headerBlock), reference, false);
return new ListItemBlock(Collections.singletonList(linkBlock));
......
.runTransformations
.#-----------------------------------------------------
.input|xwiki/2.0
.# Verify that the toc uses manually specified ids.
.#-----------------------------------------------------
{{toc/}}
(% id="somenewid" %)
= h1 =
== h2 ==
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginMacroMarkerStandalone [toc] []
beginList [BULLETED]
beginListItem
beginLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [somenewid]]] [false]
onWord [h1]
endLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [somenewid]]] [false]
beginList [BULLETED]
beginListItem
beginLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [Hh2]]] [false]
onWord [h2]
endLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [Hh2]]] [false]
endListItem
endList [BULLETED]
endListItem
endList [BULLETED]
endMacroMarkerStandalone [toc] []
beginSection
beginHeader [1, Hh1] [[id]=[somenewid]]
onWord [h1]
endHeader [1, Hh1] [[id]=[somenewid]]
beginSection
beginHeader [2, Hh2]
onWord [h2]
endHeader [2, Hh2]
endSection
endSection
endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<ul><li><span class="wikilink"><a href="#somenewid">h1</a></span><ul><li><span class="wikilink"><a href="#Hh2">h2</a></span></li></ul></li></ul><h1 id="somenewid"><span>h1</span></h1><h2 id="Hh2" class="wikigeneratedid"><span>h2</span></h2>
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<!--startmacro:toc|-|--><ul><li><!--startwikilink:#somenewid--><span class="wikilink"><a href="#somenewid">h1</a></span><!--stopwikilink--><ul><li><!--startwikilink:#Hh2--><span class="wikilink"><a href="#Hh2">h2</a></span><!--stopwikilink--></li></ul></li></ul><!--stopmacro--><h1 id="somenewid"><span>h1</span></h1><h2 id="Hh2" class="wikigeneratedid"><span>h2</span></h2>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment