From 79af3c4c75b4e00d47e24c8f7ca08b366f00a98f Mon Sep 17 00:00:00 2001 From: "Suraj Kekagit config --global user.email j8@gmail.c" Date: Fri, 9 Jan 2026 09:13:13 +0530 Subject: [PATCH] docs: Add copy button to code blocks. Configure the copy button to exclude prompts and line numbers. --- docs/conf.py | 3 +++ pyproject.toml | 3 ++- uv.lock | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 10eb2c3b7b..510b68e994 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,6 +20,7 @@ extensions = [ "myst_parser", "sphinx_rtd_theme", "sphinx_design", + "sphinx_copybutton", ] templates_path = ["_templates"] project = "Zulip" @@ -57,6 +58,8 @@ html_theme_options = { } html_logo = "images/zulip-logo.svg" html_static_path = ["_static"] +# When copying code blocks, ignore line numbers and prompts +copybutton_exclude = ".linenos, .gp" def setup(app: Any) -> None: diff --git a/pyproject.toml b/pyproject.toml index 297385e9d7..724a362f6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -221,7 +221,8 @@ docs = [ "sphinx<8.2", # 8.2.0 requires Python ≥ 3.11 "sphinx-rtd-theme", "sphinx-design", - + # Needed for copybutton + "sphinx-copybutton", # Needed to build Markdown docs "myst-parser", ] diff --git a/uv.lock b/uv.lock index e180a7673a..d0d9cfd0aa 100644 --- a/uv.lock +++ b/uv.lock @@ -4966,6 +4966,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/26/60/1ddff83a56d33aaf6f10ec8ce84b4c007d9368b21008876fceda7e7381ef/sphinx-8.1.3-py3-none-any.whl", hash = "sha256:09719015511837b76bf6e03e42eb7595ac8c2e41eeb9c29c5b755c6b677992a2", size = 3487125, upload-time = "2024-10-13T20:27:10.448Z" }, ] +[[package]] +name = "sphinx-copybutton" +version = "0.5.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "sphinx" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/fc/2b/a964715e7f5295f77509e59309959f4125122d648f86b4fe7d70ca1d882c/sphinx-copybutton-0.5.2.tar.gz", hash = "sha256:4cf17c82fb9646d1bc9ca92ac280813a3b605d8c421225fd9913154103ee1fbd", size = 23039, upload-time = "2023-04-14T08:10:22.998Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9e/48/1ea60e74949eecb12cdd6ac43987f9fd331156388dcc2319b45e2ebb81bf/sphinx_copybutton-0.5.2-py3-none-any.whl", hash = "sha256:fb543fd386d917746c9a2c50360c7905b605726b9355cd26e9974857afeae06e", size = 13343, upload-time = "2023-04-14T08:10:20.844Z" }, +] + [[package]] name = "sphinx-design" version = "0.6.1" @@ -6359,6 +6371,7 @@ dev = [ { name = "social-auth-app-django" }, { name = "social-auth-core", extra = ["azuread", "saml"] }, { name = "sphinx" }, + { name = "sphinx-copybutton" }, { name = "sphinx-design" }, { name = "sphinx-rtd-theme" }, { name = "sqlalchemy", extra = ["mypy"] }, @@ -6403,6 +6416,7 @@ dev = [ docs = [ { name = "myst-parser" }, { name = "sphinx" }, + { name = "sphinx-copybutton" }, { name = "sphinx-design" }, { name = "sphinx-rtd-theme" }, ] @@ -6596,6 +6610,7 @@ dev = [ { name = "social-auth-app-django" }, { name = "social-auth-core", extras = ["azuread", "saml"] }, { name = "sphinx", specifier = "<8.2" }, + { name = "sphinx-copybutton" }, { name = "sphinx-design" }, { name = "sphinx-rtd-theme" }, { name = "sqlalchemy", specifier = "==1.4.*" }, @@ -6641,6 +6656,7 @@ dev = [ docs = [ { name = "myst-parser" }, { name = "sphinx", specifier = "<8.2" }, + { name = "sphinx-copybutton" }, { name = "sphinx-design" }, { name = "sphinx-rtd-theme" }, ]