Skip to content

Add the sphinx-copybutton extension for easier copying codes #833

@seisman

Description

@seisman

Description of the desired feature

The examples in the docstring have Python prompt likes >>> and ..., which makes it difficult to copy. For example, https://www.pygmt.org/dev/api/generated/pygmt.datasets.load_earth_relief.html#pygmt.datasets.load_earth_relief.

Directly copy the codes gives me the following codes:

>>> # load the default grid (pixel-registered 01d grid)
>>> grid = load_earth_relief()
>>> # load the 30m grid with "gridline" registration
>>> grid = load_earth_relief("30m", registration="gridline")
>>> # load high-resolution grid for a specific region
>>> grid = load_earth_relief(
...     "05m", region=[120, 160, 30, 60], registration="gridline"
... )

which is not ready for use.

The sphinx-copybutton extension can add a copy button to code blocks so readers can copy the codes by clicking the button. It can also strip the prompts.

I think the extension would make the documentation easier to use. What do you think @GenericMappingTools/python.

Are you willing to help implement and maintain this feature? Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationfeature requestNew feature wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions