Skip to content

Add copy-to-clipboard functionality to documentation code blocks#11

Open
sarcaxticlarka wants to merge 1 commit intooppia:masterfrom
sarcaxticlarka:add-copy-code-buttons
Open

Add copy-to-clipboard functionality to documentation code blocks#11
sarcaxticlarka wants to merge 1 commit intooppia:masterfrom
sarcaxticlarka:add-copy-code-buttons

Conversation

@sarcaxticlarka
Copy link

Overview

  1. This PR fixes or fixes part of N/A (new feature enhancement)
  2. This PR does the following: Adds copy-to-clipboard buttons to all code blocks in documentation pages. Users can click a clipboard icon to instantly copy code examples. Includes visual feedback with checkmark and blue highlight on successful copy.

Essential Checklist

  • I have followed the build process and verified changes work locally
  • The linter/Karma presubmit checks pass on my local machine
  • "Allow edits from maintainers" is checked

Changes Made

New Files:

  • site/doc/copy-code.css - Button styling with SVG clipboard icons
  • site/doc/copy-code.js - Copy functionality with Clipboard API + fallback

Modified Files:

  • Updated 12 documentation HTML files to include copy-code assets

Total: 14 files changed, 138+ lines added

Implementation Details

  • Pure vanilla JavaScript (zero dependencies)
  • Modern Clipboard API with document.execCommand fallback
  • Absolute positioning (top-right) to avoid code layout disruption
  • Visual feedback: checkmark icon + blue highlight for 2 seconds
  • SVG icons: clipboard outline → checkmark on success
  • Works on all browsers (tested Chrome, Firefox, Safari)

Testing

✅ Tested locally on http://127.0.0.1:8066
✅ All 12 documentation pages working correctly
✅ No console errors
✅ Copy functionality verified
✅ Visual feedback displays properly
✅ Layout remains intact (no disruption)

Files Updated

  1. site/doc/quickstart.html
  2. site/doc/script.html
  3. site/doc/style.html
  4. site/doc/render.html
  5. site/doc/symbols.html
  6. site/doc/version.html
  7. site/doc/format.html
  8. site/doc/internals.html
  9. site/doc/faq.html
  10. site/doc/roadmap.html
  11. site/doc/index.html
  12. site/contribute/index.html

Note

This PR only enhances documentation UX and doesn't modify Guppy's core functionality or package.json. Changes are isolated to static HTML documentation pages only.

Screenshot 2025-11-26 at 10 35 47 AM

- Created copy-code.css for button styling with clipboard SVG icons
- Created copy-code.js for copy functionality with modern Clipboard API and fallback
- Updated 12 documentation HTML files to include copy-code assets
- Button positioned absolutely (top-right) to avoid code layout disruption
- Visual feedback with blue highlight and checkmark icon when copied
- No dependencies, pure vanilla JavaScript implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant