docs: add copy buttons for code blocks
PATCH 1/1 docs: add copy buttons for code blocks
Add a copy button to highlighted code blocks in the documentation that copies the full contents of the code block to the clipboard.
This is faster and less error-prone than manually selecting and copying code from the page, especially for longer examples where part of the block can be accidentally missed.
Keep the control hidden until the user interacts with the block so it stays out of the way during normal reading. Reveal it on hover, focus, and touch interaction, then copy the block contents to the clipboard with a small success or failure state.
---
Live demo:
https://kernel-docs-cp.ritovision.com/accounting/delay-accounting.html
I am willing to maintain this small feature and handle follow-up fixes if problems come up. I do not expect it to expand significantly beyond its current scope.
Documentation/conf.py +1 -0
@@ -376,6 +376,7 @@ highlight_language = "none" # Default theme html_theme = "alabaster" html_css_files = [] +html_js_files = ["copy-code.js"] if "DOCS_THEME" in os.environ: html_theme = os.environ["DOCS_THEME"]
Documentation/sphinx-static/copy-code.js new file +147 -0
147 lines not on this page · raw message
Documentation/sphinx-static/custom.css +73 -0
76 lines not on this page · raw message
MAINTAINERS +6 -0
@@ -7652,6 +7652,12 @@ X: Documentation/power/ X: Documentation/spi/ X: Documentation/userspace-api/media/ +DOCUMENTATION COPY CODE BUTTON +R: Rito Rhymes <[email protected]> +L: [email protected] +S: Supported +F: Documentation/sphinx-static/copy-code.js + DOCUMENTATION PROCESS M: Jonathan Corbet <[email protected]> R: Shuah Khan <[email protected]>
Signature · 1 line
2.51.0
Jonathan Corbet
maintainerQuoted 12 lines · Rito Rhymes
Add a copy button to highlighted code blocks in the documentation that copies the full contents of the code block to the clipboard.
This is faster and less error-prone than manually selecting and copying code from the page, especially for longer examples where part of the block can be accidentally missed.
Keep the control hidden until the user interacts with the block so it stays out of the way during normal reading. Reveal it on hover, focus, and touch interaction, then copy the block contents to the clipboard with a small success or failure state.
Quoted 6 lines
---
Live demo:
https://kernel-docs-cp.ritovision.com/accounting/delay-accounting.html
Honestly, I don't think so.
Rito, who is asking for this feature? What is the use case? Does it really justify adding a blob of JavaScript code to every view of the kernel documentation - JavaScript that we will have to maintain going forward?
Our goal here is to make the kernel documentation better, not to shovel lots of code into the repository.
If you can get some acks from established kernel developers saying that they want this change, I will reconsider - but only after the merge window. But I really think that, again, this is something you might want to discuss with the Sphinx developers, then turn it into something without hard-coded colors that will work with whatever theme people might choose to build their docs with.
jon