[ https://issues.apache.org/jira/browse/DOXIASITETOOLS-320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17790700#comment-17790700 ]
ASF GitHub Bot commented on DOXIASITETOOLS-320: ----------------------------------------------- kwin commented on code in PR #180: URL: https://github.com/apache/maven-doxia/pull/180#discussion_r1408134053 ########## doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/NamesForIndexEntriesSinkWrapper.java: ########## @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.doxia.sink.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.doxia.index.IndexEntry; +import org.apache.maven.doxia.index.SectionLocation; +import org.apache.maven.doxia.macro.toc.TocMacro; +import org.apache.maven.doxia.parser.SinkWrapper; +import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributes; + +/** + * Sink wrapper which emits anchors for each section represented by the given {@link IndexEntry}. + * @see TocMacro + */ +public class NamesForIndexEntriesSinkWrapper extends SinkWrapper { + + private final Map<SectionLocation, IndexEntry> entryByLocation; + private SectionLocation currentLocation; + + public NamesForIndexEntriesSinkWrapper(Sink delegate, IndexEntry index) { + super(delegate); + entryByLocation = new HashMap<>(); + populateMap(entryByLocation, index); + this.currentLocation = new SectionLocation(); + } + + private static void populateMap(Map<SectionLocation, IndexEntry> entryByLocation, IndexEntry entry) { + entryByLocation.put(entry.getLocation(), entry); + entry.getChildEntries().forEach(e -> populateMap(entryByLocation, e)); + } + + @Override + public void section(int level, SinkEventAttributes attributes) { + onStartSection(level); + super.section(level, attributes); + } + + @Override + public void section_(int level) { + super.section_(level); + onEndSection(); + } + + @Override + public void section1() { + super.section1(); + onStartSection(1); + } + + @Override + public void section1_() { + super.section1_(); + onEndSection(); + } + + @Override + public void section2() { + super.section2(); + onStartSection(2); + } + + @Override + public void section2_() { + super.section2_(); + onEndSection(); + } + + @Override + public void section3() { + super.section3(); + onStartSection(3); + } + + @Override + public void section3_() { + super.section3_(); + onEndSection(); + } + + @Override + public void section4() { + super.section4(); + onStartSection(4); + } + + @Override + public void section4_() { + super.section4_(); + onEndSection(); + } + + @Override + public void section5() { + super.section5(); + onStartSection(5); + } + + @Override + public void section5_() { + super.section5_(); + onEndSection(); + } + + private void onStartSection(int level) { + currentLocation = currentLocation.createChildSection(level); + IndexEntry entry = entryByLocation.get(currentLocation); + if (entry != null) { Review Comment: Probably a guard similar to https://github.com/apache/maven-doxia-sitetools/pull/58/files#diff-dabe16ceeba5dc7cb0a15e30dcb7c204a78f4763346f016ab7639ab2f59e78d4L250 needs to be introduced to at least prevent double anchors for APT format. > Inconsistent anchors between toc macro and headers > -------------------------------------------------- > > Key: DOXIASITETOOLS-320 > URL: https://issues.apache.org/jira/browse/DOXIASITETOOLS-320 > Project: Maven Doxia Sitetools > Issue Type: Bug > Components: Site renderer > Reporter: Slawomir Jaranowski > Assignee: Konrad Windszus > Priority: Critical > > In markdown document add: > {code:java} > <!-- MACRO{toc|fromDepth=2} --> > {code} > Then anchors generated by toc macro looks like: {{#Your_First_Mojo}} > and anchors generated by skin looks like: {{#your-first-plugin}} > - Doxia Site Renderer 2.0.0-M4 > - Fluido Skin 1.11.1 > Tested on Maven main site without more investigate. -- This message was sent by Atlassian Jira (v8.20.10#820010)