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

ENH: Directly add SVG instead of linking via IMG #161

Merged
merged 8 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Deprecate old image path
  • Loading branch information
choldgraf committed Feb 3, 2022
commit 754af952964879a3385c19426019328bb76901db
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
# Switches for testing but shouldn't be activated in the live docs
# copybutton_only_copy_prompt_lines = False
# copybutton_remove_prompts = False
# copybutton_image_path = "_static/clipboard.svg" # DEPRECATED: remove after next release # noqa: E501
# copybutton_image_svg = """
# <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round"> # noqa: E501
# <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
Expand Down
2 changes: 1 addition & 1 deletion docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ For example, if you wanted to use a **clipboard icon** instead of the default co
1. Copy the `Clipboard Icon SVG` from [the Tabular icons pack](https://tablericons.com/).
Here is the SVG for reference:

```svg
```
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2" />
Expand Down
15 changes: 15 additions & 0 deletions sphinx_copybutton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ def add_to_context(app, config):
config.html_context.update(
{"copybutton_here_doc_delimiter": config.copybutton_here_doc_delimiter}
)

# Old image path deprecation
# REMOVE after next release
if config.copybutton_image_path:
path = Path(app.srcdir) / config.copybutton_image_path
logger.warning("copybutton_image_path is deprecated, use copybutton_image_svg")
if not path.exists():
raise ValueError("copybutton_img_path does not exist")
if not path.suffix == ".svg":
raise ValueError("copybutton_img_path must be an SVG")
config.copybutton_image_svg = path.read_text()

config.html_context.update({"copybutton_image_svg": config.copybutton_image_svg})
config.html_context.update({"copybutton_selector": config.copybutton_selector})
config.html_context.update(
Expand Down Expand Up @@ -69,6 +81,9 @@ def setup(app):
app.add_config_value("copybutton_image_svg", "", "html")
app.add_config_value("copybutton_selector", "div.highlight pre", "html")

# DEPRECATE THIS AFTER THE NEXT RELEASE
app.add_config_value("copybutton_image_path", "", "html")

# Add configuration value to the template
app.connect("config-inited", add_to_context)

Expand Down