Skip to content

Commit ea678b9

Browse files
author
Release Manager
committed
gh-35304: HTML documentation: Add copy buttons to code blocks <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description A copy button is added to the top right of each code block in the HTML documentation. Key added functionality, compared to just selecting the code and copy- pasting it to a Sage session: - it's just one click - the output of doctests is omitted - comments (in particular the many new `# optional - ...` comments) are stripped away Example: https://deploy-preview-35304--sagemath-tobias.netlify.app/refer ence/discrete_geometry/sage/geometry/polyhedron/base7.html#sage.geometry .polyhedron.base7.Polyhedron_base7.volume Resolves #35239 <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35304 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Tobias Diez
2 parents bbedc68 + ebe73c9 commit ea678b9

File tree

9 files changed

+39
-2
lines changed

9 files changed

+39
-2
lines changed

build/pkgs/sagemath_doc_html/dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sagelib sphinx pplpy_doc | $(SAGERUNTIME) maxima networkx scipy sympy matplotlib pillow mathjax mpmath ipykernel jupyter_client conway_polynomials tachyon jmol ipywidgets jupyter_sphinx sage_docbuild elliptic_curves furo fpylll
1+
sagelib sphinx sphinx_copybutton pplpy_doc | $(SAGERUNTIME) maxima networkx scipy sympy matplotlib pillow mathjax mpmath ipykernel jupyter_client conway_polynomials tachyon jmol ipywidgets jupyter_sphinx sage_docbuild elliptic_curves furo fpylll
22

33
# Building the documentation has many dependencies, because all
44
# documented modules are imported and because we use matplotlib to

build/pkgs/sphinx_copybutton/SPKG.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sphinx_copybutton: Add a copy button to each of your code cells.
2+
================================================================
3+
4+
Description
5+
-----------
6+
7+
Add a copy button to each of your code cells.
8+
9+
License
10+
-------
11+
12+
MIT License
13+
14+
Upstream Contact
15+
----------------
16+
17+
https://pypi.org/project/sphinx-copybutton/
18+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tarball=sphinx_copybutton-VERSION-py3-none-any.whl
2+
sha1=329d24e382c80fbb39aba221479f3ca3f566d19c
3+
md5=1181950a5fd59160f7ec588e805d986f
4+
cksum=142562474
5+
upstream_url=https://pypi.io/packages/py3/s/sphinx_copybutton/sphinx_copybutton-VERSION-py3-none-any.whl
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(PYTHON) sphinx | $(PYTHON_TOOLCHAIN)
2+
3+
----------
4+
All lines of this file are ignored except the first.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sphinx-copybutton
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.1

build/pkgs/sphinx_copybutton/type

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
standard

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ AC_ARG_ENABLE([doc],
496496
AS_HELP_STRING([--disable-doc],
497497
[disable build of the Sage documentation and packages depending on it]), [
498498
dnl Disable packages needed for docbuilding
499-
for pkg in sage_docbuild alabaster babel snowballstemmer imagesize sphinx sphinxcontrib_devhelp sphinxcontrib_jsmath sphinxcontrib_serializinghtml sphinxcontrib_applehelp sphinxcontrib_htmlhelp sphinxcontrib_qthelp sphinxcontrib_websupport jupyter_sphinx furo; do
499+
for pkg in sage_docbuild alabaster babel snowballstemmer imagesize sphinx sphinxcontrib_devhelp sphinxcontrib_jsmath sphinxcontrib_serializinghtml sphinxcontrib_applehelp sphinxcontrib_htmlhelp sphinxcontrib_qthelp sphinxcontrib_websupport jupyter_sphinx furo sphinx_copybutton; do
500500
AS_VAR_SET([SAGE_ENABLE_$pkg], [$enableval])
501501
done
502502
AS_VAR_IF([enableval], [no], [dnl Disable the docbuild by disabling the install tree for documentation

src/sage_docbuild/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'sphinx.ext.todo',
4747
'sphinx.ext.extlinks',
4848
'sphinx.ext.mathjax',
49+
'sphinx_copybutton',
4950
'IPython.sphinxext.ipython_directive',
5051
'matplotlib.sphinxext.plot_directive',
5152
'jupyter_sphinx',
@@ -255,6 +256,12 @@ def set_intersphinx_mappings(app, config):
255256
# By default document are not master.
256257
multidocs_is_master = True
257258

259+
# https://sphinx-copybutton.readthedocs.io/en/latest/use.html
260+
copybutton_prompt_text = r"sage: |[.][.][.][.]: |\$ "
261+
copybutton_prompt_is_regexp = True
262+
copybutton_exclude = '.linenos, .c1' # exclude single comments (in particular, # optional!)
263+
copybutton_only_copy_prompt_lines = True
264+
258265
# Options for HTML output
259266
# -----------------------
260267

0 commit comments

Comments
 (0)