Skip to content

sphinx.ext.extlinks: Allow Callback for URL Format String #1622

@shimizukawa

Description

@shimizukawa

It would be nice if instead of a formatting string, you could pass a callable that returns the combined URL for extlinks. This would allow cases where the input part isn't quite part of the url.

For example, this Docker reference uses lowercase anchors, but uppercase section titles: https://docs.docker.com/reference/builder/

Here's my current extlinks config:

    'Dockerfile': (
        'https://docs.docker.com/reference/builder/#%s',
        ''
    )

To handle the difference in captalization, I need to link as follows:

:Dockerfile:`RUN <run>`

It would be preferable to define the extlink using a callable handling the case conversion:

    'Dockerfile': (
        lambda part: 'https://docs.docker.com/reference/builder/#%s' % part.lower(),
        ''
    )

I suspect this is one of many possible use cases that would benefit. And since you could test for a callable vs a string, it should be fully backwards compatible.


Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions