Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong refid when SEPARATE_MEMBER_PAGES is YES #566

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions breathe/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def setup(app: Sphinx) -> None:
app.add_config_value("breathe_doxygen_config_options", {}, True)
app.add_config_value("breathe_use_project_refids", False, "env")
app.add_config_value("breathe_order_parameters_first", False, 'env')
app.add_config_value("breathe_separate_member_pages", False, 'env')

breathe_css = "breathe.css"
if (os.path.exists(os.path.join(app.confdir, "_static", breathe_css))):
Expand Down
37 changes: 37 additions & 0 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,44 @@ def set_context(self, context: RenderContext) -> None:
if self.context.domain == '':
self.context.domain = self.get_domain()

# XXX: fix broken links in XML generated by Doxygen when Doxygen's
# SEPARATE_MEMBER_PAGES is set to YES; this function should be harmless
# when SEPARATE_MEMBER_PAGES is NO!
#
# The issue was discussed here: https://github.com/doxygen/doxygen/pull/7971
#
# A Doxygen anchor consists of a 32-byte string version of the results of
# passing in the stringified identifier or prototype that is being "hashed".
# An "a" character is then prefixed to mark it as an anchor. Depending on how
# the identifier is linked, it can also get a "g" prefix to mean it is part
# of a Doxygen group. This results in an id having either 33 or 34 bytes
# (containing a "g" or not). Some identifiers, eg enumerators, get twice that
# length to have both a unique enum + unique enumerator, and sometimes they
# get two "g" characters as prefix instead of one.
def _fixup_separate_member_pages(self, refid: str) -> str:
if refid:
parts = refid.rsplit("_", 1)
if len(parts) == 2 and parts[1].startswith("1"):
anchorid = parts[1][1:]
if len(anchorid) in set([33, 34]) and parts[0].endswith(anchorid):
return parts[0][:-len(anchorid)] + parts[1]
elif len(anchorid) > 34:
index = 0
if anchorid.startswith('gg'):
index = 1
_len = 35
elif anchorid.startswith('g'):
_len = 34
else:
_len = 33
if parts[0].endswith(anchorid[index:_len]):
return parts[0][:-(_len - index)] + parts[1]

return refid

def get_refid(self, refid: str) -> str:
if self.app.config.breathe_separate_member_pages: # type: ignore
refid = self._fixup_separate_member_pages(refid)
if self.app.config.breathe_use_project_refids: # type: ignore
return "%s%s" % (self.project_info.name(), refid)
else:
Expand Down
8 changes: 8 additions & 0 deletions documentation/source/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,11 @@ Config Values
documentation should be placed immediately after the brief and detailed description
or at the end, after the returns, remarks and warnings section. Default value and
also the legacy behavior is False.

.. confval:: breathe_separate_member_pages

True or False setting to control if the input XML generated by Doxygen had the
Doxygen SEPARATE_MEMBER_PAGES option set to YES or NO. The Doxygen option defaults
to NO which generates XML that allows Breathe to resolve all references. When set
to YES the refid/id of elements get an extra element which Breathe tries to get rid
of when this setting is True.
1 change: 1 addition & 0 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def render(app, member_def, domain=None, show_define_initializer=False,
compound_parser=None, options=[]):
"""Render Doxygen *member_def* with *renderer_class*."""

app.config.breathe_separate_member_pages = False
app.config.breathe_use_project_refids = False
app.config.breathe_show_define_initializer = show_define_initializer
app.config.breathe_debug_trace_directives = False
Expand Down