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

New feature: linking to source files at arbitrary URLs #1013

Open
Lucas-C opened this issue Jan 17, 2025 · 0 comments
Open

New feature: linking to source files at arbitrary URLs #1013

Lucas-C opened this issue Jan 17, 2025 · 0 comments

Comments

@Lucas-C
Copy link

Lucas-C commented Jan 17, 2025

Hi.

Feature request

Would it be possible to generate links to source files in arbitrary git repositories (GitHub, Gitlab....)
when inserting doxygen* directives?

Feature proposal

A new optional breathe configuration setting:

breathe_file_src_url = "https://github.com/breathe-doc/breathe/blob/master/{file_path}#L{line}"

Demo

I submitted a monkey-patch based solution in this PR on a project using breathe: motis-project/utl#30

Resulting documentation: https://motis-project.github.io/utl/#api-details

Relevant code in conf.py:

html_theme = 'sphinx_rtd_theme'
html_theme_options = {
    'style_external_links': True,
}

from pathlib import Path
from docutils import nodes
from breathe.renderer.sphinxrenderer import SphinxRenderer

breathe_file_src_url = "https://github.com/motis-project/utl/blob/master/{file_path}#L{line}"
REPO_ROOT_DIR = Path(__file__).parent.parent

def create_doxygen_target(self, node):
    loc = node.location
    file_path = loc.file[len(str(REPO_ROOT_DIR))+1:]
    url = breathe_file_src_url.format(file_path=file_path, line=loc.line)
    title = f"{file_path} on line {loc.line}"
    return [nodes.reference("", "", refuri=url, reftitle=title)]

# Monkey patching this method:
SphinxRenderer.create_doxygen_target = create_doxygen_target

Extract from index.md (this project uses Markdown instead of reStructuredText):

:::{doxygenstruct} utl::log
:no-link:
:members:
:::

Notes

Related issues

Implementation

This solution uses .reference.external HTML <a> links,
in combination with the :no-link: option
and style_external_links=True in the theme used.

A cleaner solution could be to use the definition (🔗) links instead,
that are inserted by default when no-link is not specified.

Also this implementation does not take care to distinguish links to source files from other kind of URLs
(e.g. generated by docurllink). Some care should be taken regarding this in the final implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant