diff --git a/breathe/renderer/target.py b/breathe/renderer/target.py index e08f772f..b6eb962e 100644 --- a/breathe/renderer/target.py +++ b/breathe/renderer/target.py @@ -16,9 +16,26 @@ def __init__(self, project_info: ProjectInfo, document: nodes.document): self.project_info = project_info self.document = document + # XXX: when inside a group in Doxygen, if the XML generator finds a + # reference in a comment, it generates a new element where the refid + # gets both a compoundid and an anchorid, where: anchorid = "_1" + compoundid. + # In the group__*.xml files the ids that are linked to, only get the + # anchorid (or "_1" + compoundid!). + # This function tries to detect if the anchor is not present twice, and + # fixup the ref id so that the final symbol resolution works. + def _fixup_target(self, refid: str) -> str: + if refid: + parts = refid.rsplit("_", 1) + if len(parts) == 2 and parts[1].startswith("1"): + anchorid = parts[1][1:] + if anchorid not in parts[0]: + return "_".join([parts[0], anchorid, parts[1]]) + return refid + def create_target(self, refid: str) -> List[Element]: """Creates a target node and registers it with the document and returns it in a list""" + refid = self._fixup_target(refid) target = nodes.target(ids=[refid], names=[refid]) try: self.document.note_explicit_target(target)