Skip to content

Commit

Permalink
Fix wrong refid in Doxygen's XML generator
Browse files Browse the repository at this point in the history
Given the following Doxygen input:

```
/**
 * This struct must be used with f()
 */
struct t {
  int x;
}

/**
 * @param tx A struct t pointer
 */
void f(struct t *tx) {
  (void)tx;
}
```

The `f()` in struct t's comment generates a <ref> element with `refid`
equal to `some_prefix_compoundid_anchorid`, wheres the `id` in the
refered element ends up with an `id` equal to `some_prefix_anchorid`.
The anchorid here is just the compoundid prefix by "_1", so the `refid`
actually has this information duplicated.

This is a band-aid solution that tries to detect the issue in the ref
ids and adds the duplication, so that resulting links work.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
  • Loading branch information
utzig committed Aug 19, 2020
1 parent 26cd84d commit c8e2767
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions breathe/renderer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ref> 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)
Expand Down

0 comments on commit c8e2767

Please sign in to comment.