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: code copy button #1465

Merged
merged 3 commits into from
Aug 17, 2023
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
18 changes: 18 additions & 0 deletions docs/demo/code-blocks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,21 @@ If you don't include any markup, the content is rendered with syntax highlightin
.. seealso::

`Parsed-literal directive (docutils) <https://docutils.sourceforge.io/docs/ref/rst/directives.html#code>`_

Prompt characters
-----------------

Prompt characters shouldn't be selected when copying code.

For example, if you copy the code from the following ``console`` code block,
the ``$`` character should not be copied:

.. code-block:: console

$ echo "Prompt characters not selected"

The same is true for Python interactive sessions:

.. code-block:: pycon

>>> print("Prompt characters not selected.")
894 changes: 496 additions & 398 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.8"
sphinx = ">4"
sphinx = ">4, <7.2"
beautifulsoup4 = "^4.9.1"

[tool.poetry.group.docs.dependencies]
Expand Down
14 changes: 8 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
argcomplete==3.1.1 ; python_version == "3.8"
attrs==23.1.0 ; python_version == "3.8"
build==0.10.0 ; python_version == "3.8"
cachecontrol[filecache]==0.12.13 ; python_version == "3.8"
cachecontrol[filecache]==0.12.14 ; python_version == "3.8"
certifi==2023.7.22 ; python_version == "3.8"
cffi==1.15.1 ; (sys_platform == "darwin" or sys_platform == "linux") and python_version == "3.8"
charset-normalizer==3.2.0 ; python_version == "3.8"
cleo==2.0.1 ; python_version == "3.8"
click==8.1.5 ; python_version == "3.8"
click==8.1.6 ; python_version == "3.8"
colorama==0.4.6 ; python_version == "3.8" and (sys_platform == "win32" or os_name == "nt" or platform_system == "Windows")
colorlog==6.7.0 ; python_version == "3.8"
crashtest==0.4.1 ; python_version == "3.8"
Expand All @@ -17,14 +17,15 @@ filelock==3.12.2 ; python_version == "3.8"
html5lib==1.1 ; python_version == "3.8"
idna==3.4 ; python_version == "3.8"
importlib-metadata==6.8.0 ; python_version == "3.8"
importlib-resources==6.0.0 ; python_version == "3.8"
importlib-resources==6.0.1 ; python_version == "3.8"
installer==0.7.0 ; python_version == "3.8"
jaraco-classes==3.3.0 ; python_version == "3.8"
jeepney==0.8.0 ; sys_platform == "linux" and python_version == "3.8"
jsonschema-specifications==2023.7.1 ; python_version == "3.8"
jsonschema==4.19.0 ; python_version == "3.8"
keyring==23.13.1 ; python_version == "3.8"
lockfile==0.12.2 ; python_version == "3.8"
more-itertools==10.0.0 ; python_version == "3.8"
more-itertools==10.1.0 ; python_version == "3.8"
msgpack==1.0.5 ; python_version == "3.8"
nox==2023.4.22 ; python_version == "3.8"
packaging==23.1 ; python_version == "3.8"
Expand All @@ -40,13 +41,14 @@ poetry==1.5.1 ; python_version == "3.8"
ptyprocess==0.7.0 ; python_version == "3.8"
pycparser==2.21 ; python_version == "3.8" and (sys_platform == "darwin" or sys_platform == "linux")
pyproject-hooks==1.0.0 ; python_version == "3.8"
pyrsistent==0.19.3 ; python_version == "3.8"
pywin32-ctypes==0.2.2 ; sys_platform == "win32" and python_version == "3.8"
rapidfuzz==2.15.1 ; python_version == "3.8"
referencing==0.30.2 ; python_version == "3.8"
requests-toolbelt==1.0.0 ; python_version == "3.8"
requests==2.31.0 ; python_version == "3.8"
rpds-py==0.9.2 ; python_version == "3.8"
secretstorage==3.3.3 ; sys_platform == "linux" and python_version == "3.8"
shellingham==1.5.0.post1 ; python_version == "3.8"
shellingham==1.5.3 ; python_version == "3.8"
six==1.16.0 ; python_version == "3.8"
tomli==2.0.1 ; python_version == "3.8"
tomlkit==0.12.1 ; python_version == "3.8"
Expand Down
3 changes: 2 additions & 1 deletion src/sphinxawesome_theme/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from __future__ import annotations

import os
import pathlib
import re
from dataclasses import dataclass

Expand All @@ -41,7 +42,7 @@ class Icons:
permalinks_icon: str = '<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 24 24"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'


def _get_html_files(outdir: str) -> list[str]:
def _get_html_files(outdir: pathlib.Path | str) -> list[str]:
"""Get a list of HTML files."""
html_list = []
for root, _, files in os.walk(outdir):
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! @docsearch/js 3.5.1 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
Binary file not shown.
Binary file not shown.
32 changes: 16 additions & 16 deletions src/sphinxawesome_theme/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"_static/theme.css": "_static/theme.3849c567b4e07dd3db70.css",
"_static/theme.js": "_static/theme.8ffe40a2eae52cc22aaf.js",
"_static/docsearch.css": "_static/docsearch.85d5398a6bda019d8011.css",
"_static/docsearch.js": "_static/docsearch.0d41323c78ab115fe2db.js",
"_static/theme.css": "_static/theme.d5da1ae72e45df4c5b8e.css",
"_static/theme.js": "_static/theme.83923940ee80f2e3f0bf.js",
"_static/docsearch.css": "_static/docsearch.83e8e0316c3f553350c3.css",
"_static/docsearch.js": "_static/docsearch.f87705adb523b39a3d6c.js",
"_static/awesome-sphinx-design.css": "_static/awesome-sphinx-design.495717882cf46c002fb5.css",
"_static/awesome-sphinx-design.js": "_static/awesome-sphinx-design.31d6cfe0d16ae931b73c.js",
"_static/jetbrains-mono-latin-500-italic.woff": "_static/5b12b1b913a1d0348fc6.woff",
"_static/jetbrains-mono-latin-700-italic.woff": "_static/b8546ea1646db8ea9c7f.woff",
"_static/jetbrains-mono-latin-400-italic.woff": "_static/f509ddf49c74ded8c0ee.woff",
"_static/jetbrains-mono-latin-700-normal.woff": "_static/3925889378745d0382d0.woff",
"_static/jetbrains-mono-latin-500-normal.woff": "_static/26400cae88e50682937d.woff",
"_static/jetbrains-mono-latin-400-normal.woff": "_static/6c1a3008005254946aef.woff",
"_static/jetbrains-mono-latin-700-italic.woff2": "_static/aef37e2fab43d03531cd.woff2",
"_static/jetbrains-mono-latin-500-italic.woff2": "_static/c10c163dd1c289f11c49.woff2",
"_static/jetbrains-mono-latin-400-italic.woff2": "_static/2a472f0334546ace60b3.woff2",
"_static/jetbrains-mono-latin-500-normal.woff2": "_static/0ff19efc74e94c856af0.woff2",
"_static/jetbrains-mono-latin-700-normal.woff2": "_static/f4604891b5f1fc1bdbe5.woff2",
"_static/jetbrains-mono-latin-400-normal.woff2": "_static/4163112e566ed7697acf.woff2",
"_static/jetbrains-mono-latin-500-italic.woff": "_static/63a0f5d460fb58135365.woff",
"_static/jetbrains-mono-latin-700-italic.woff": "_static/1d5fc702ab9000c3247a.woff",
"_static/jetbrains-mono-latin-400-italic.woff": "_static/70e1dc5f5622381d6e9e.woff",
"_static/jetbrains-mono-latin-700-normal.woff": "_static/84504970850f0632d9c3.woff",
"_static/jetbrains-mono-latin-500-normal.woff": "_static/39bd78ffb50669d6855a.woff",
"_static/jetbrains-mono-latin-400-normal.woff": "_static/c226d7283d0d52c2d32c.woff",
"_static/jetbrains-mono-latin-700-italic.woff2": "_static/5f68b8c26e28d783a591.woff2",
"_static/jetbrains-mono-latin-500-italic.woff2": "_static/4f183a25813446a47ad9.woff2",
"_static/jetbrains-mono-latin-400-italic.woff2": "_static/a1e4997bd1fb9d7822e1.woff2",
"_static/jetbrains-mono-latin-700-normal.woff2": "_static/0fecf1cc5677455886b4.woff2",
"_static/jetbrains-mono-latin-500-normal.woff2": "_static/a61d04152f1635036f0d.woff2",
"_static/jetbrains-mono-latin-400-normal.woff2": "_static/2fe080a3bf49bdc12fcb.woff2",
"_static/docsearch_config.js_t": "_static/docsearch_config.js_t"
}
7 changes: 0 additions & 7 deletions src/sphinxawesome_theme/static/theme.3849c567b4e07dd3db70.css

This file was deleted.

2 changes: 2 additions & 0 deletions src/sphinxawesome_theme/static/theme.83923940ee80f2e3f0bf.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/sphinxawesome_theme/static/theme.8ffe40a2eae52cc22aaf.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/sphinxawesome_theme/static/theme.d5da1ae72e45df4c5b8e.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/theme-src/css/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
&:hover .copy {
@apply opacity-100;
}
.gp {
@apply select-none;
}
}

.literal-block-wrapper {
Expand Down
2 changes: 1 addition & 1 deletion src/theme-src/js/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function addCodeButtons() {

const clipboard = new ClipboardJS('button.copy', {
target: (trigger) => {
return trigger.parentNode
return trigger.previousElementSibling
},
})

Expand Down
10 changes: 5 additions & 5 deletions src/theme-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@fontsource/jetbrains-mono": "^5.0.8",
"@fontsource/jetbrains-mono": "^5.0.9",
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.14",
"autoprefixer": "^10.4.15",
"babel-loader": "^9.1.3",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
Expand All @@ -37,12 +37,12 @@
"eslint-plugin-tailwindcss": "^3.13.0",
"eslint-webpack-plugin": "^4.0.1",
"mini-css-extract-plugin": "^2.7.6",
"postcss": "^8.4.27",
"postcss": "^8.4.28",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.3.3",
"postcss-preset-env": "^9.1.1",
"prettier": "^3.0.1",
"prettier-plugin-tailwindcss": "^0.5.2",
"prettier": "^3.0.2",
"prettier-plugin-tailwindcss": "^0.5.3",
"stylelint": "^15.10.2",
"stylelint-config-prettier": "^9.0.5",
"stylelint-prettier": "^4.0.2",
Expand Down
Loading