From 890d07809472274c54c73117f9d4c9f4d0ee875f Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Wed, 16 Sep 2026 00:20:28 +0200 Subject: [PATCH 1/4] docs: add sphinx-copybutton and sphinx-codeautolink to docs deps --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 95919eb3..2e72f80a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,8 @@ docs = [ "sphinxcontrib-jsmath", "sphinx-favicon", "sphinx-autodoc-typehints", + "sphinx-copybutton", + "sphinx-codeautolink", ] ros-humble = [ From 0c8b16a53a32335e3772bbab526c0aa3114ac415 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Wed, 16 Sep 2026 00:21:01 +0200 Subject: [PATCH 2/4] docs: register sphinx_copybutton/sphinx_codeautolink extensions --- docs/source/conf.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index b5fcf84a..d8647679 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -15,6 +15,7 @@ # sys.path.insert(0, os.path.abspath('.')) # sys.path.insert(0, os.path.abspath('..')) +from sphinx_codeautolink import clean_ipython, clean_pycon # -- Project information ----------------------------------------------------- @@ -50,6 +51,14 @@ "sphinx_autorun", "sphinx.ext.intersphinx", "sphinx_favicon", + "sphinx_copybutton", + "sphinx_codeautolink", +] + +suppress_warnings = [ + "codeautolink.match_block", + "codeautolink.match_name", + "config.cache", # codeautolink_custom_blocks holds function refs, not picklable ] #'sphinx.ext.autosummary', # typehints_use_signature_return = True From 21ba463afff31f5c3036a3c30d724de2ae882dbf Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Wed, 16 Sep 2026 00:21:28 +0200 Subject: [PATCH 3/4] docs: configure sphinx-codeautolink and sphinx-copybutton options --- docs/source/conf.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index d8647679..c9883189 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -193,6 +193,24 @@ np.set_printoptions(precision=4, suppress=True) """ +# -------- sphinx-codeautolink options --------------------------------------------# + +codeautolink_custom_blocks = { + "pycon": clean_pycon, + "ipython": clean_ipython, + "ipython3": clean_ipython, +} +# Ensure pycon (Python console) blocks are included in the autolink search. +codeautolink_search_css_classes = ["highlight-python", "highlight-pycon"] + +# -------- sphinx-copybutton options ----------------------------------------------# +# Strip interactive prompts (Python and shell) when users copy code snippets. + +copybutton_prompt_text = r">>> |\.\.\. |\$ " +copybutton_prompt_is_regexp = True +copybutton_only_copy_prompt_lines = False +copybutton_remove_prompts = True + intersphinx_mapping = { "numpy": ("http://docs.scipy.org/doc/numpy/", None), "scipy": ("http://docs.scipy.org/doc/scipy/reference/", None), From 563de344ad4abfa8f496790896201b9ccea7d57c Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Wed, 16 Sep 2026 02:24:00 +0200 Subject: [PATCH 4/4] docs: fix :linenos: indentation mismatch in intro.rst sphinx-codeautolink's own parsing pass over code blocks is stricter than plain docutils about this pre-existing 3-space/4-space mismatch between the :linenos: option and the code content, surfacing a new 'unexpected indent' warning that was previously silently tolerated. --- docs/source/intro.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/intro.rst b/docs/source/intro.rst index 14672bd7..e1e9e93f 100644 --- a/docs/source/intro.rst +++ b/docs/source/intro.rst @@ -629,7 +629,7 @@ Graphics If ``matplotlib`` is installed then we can add 2D coordinate frames to a figure in a variety of styles: .. code-block:: python - :linenos: + :linenos: >>> trplot2( transl2(1,2), frame='A', rviz=True, width=1) >>> trplot2( transl2(3,1), color='red', arrow=True, width=3, frame='B') @@ -646,7 +646,7 @@ If a figure does not yet exist one is added. If a figure exists but there is no Similarly, we can plot 3D coordinate frames in a variety of styles: .. code-block:: python - :linenos: + :linenos: >>> trplot( transl(1,2,3), frame='A', rviz=True, width=1, dims=[0, 10, 0, 10, 0, 10]) >>> trplot( transl(3,1, 2), color='red', width=3, frame='B')