-
Notifications
You must be signed in to change notification settings - Fork 183
Added copy button feature with styled code block #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@IshikaBanga26 is attempting to deploy a commit to the Suman Kunwar's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds a copy-to-clipboard button feature for code snippets in the Tip Calculator example, along with styled code blocks for better visual presentation. However, the PR also includes several package.json dependency version changes that appear unrelated to the copy button feature and require careful review.
Key Changes
- Implements a JavaScript-based copy button with clipboard API integration for code snippets
- Adds CSS styling for code blocks with background, borders, and button hover effects
- Updates multiple npm package versions in package.json (both upgrades and downgrades)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| package.json | Updates dependency versions for cz-conventional-changelog (downgrade), gitbook-plugin-exercises (major downgrade), and honkit (major upgrade) |
| examples/Tip_Calculator/style.css | Adds CSS styles for code blocks and copy button, including duplicate .code-block rule definitions |
| examples/Tip_Calculator/script.js | Implements copy button functionality with DOM manipulation and clipboard API, but lacks error handling |
| examples/Tip_Calculator/index.html | Adds a code block example demonstrating a tip calculation function with formatting issues |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "gitbook-plugin-chapter-fold": "^0.0.4", | ||
| "gitbook-plugin-edit-link": "^2.0.2", | ||
| "gitbook-plugin-exercises": "^3.0.0", | ||
| "gitbook-plugin-exercises": "^1.0.0", |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change downgrades gitbook-plugin-exercises from ^3.0.0 to ^1.0.0. This is a major version downgrade that could remove important features or break existing functionality. Please verify if this downgrade is intentional and ensure all dependent code remains compatible with version 1.0.0.
| "gitbook-plugin-exercises": "^1.0.0", | |
| "gitbook-plugin-exercises": "^3.0.0", |
| "gitbook-plugin-sitemap": "^1.2.0", | ||
| "gitbook-plugin-theme-creative": "github:sumn2u/gitbook-plugin-theme-creative", | ||
| "honkit": "^4.0.4", | ||
| "honkit": "^6.1.4", |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change upgrades honkit from ^4.0.4 to ^6.1.4, skipping version 5 entirely. This is a major version upgrade that may include breaking changes. Please ensure all honkit plugins and configurations are compatible with version 6.1.4, and test the build thoroughly.
| .code-block { | ||
| margin-top: 20px; | ||
| } |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .code-block class is defined twice in this file (lines 36-38 and lines 68-70). The first definition sets margin-top: 20px and the second sets position: relative. These should be combined into a single rule block to avoid confusion and improve maintainability.
| const text = codeBlock.textContent; | ||
| navigator.clipboard.writeText(text).then(() => { | ||
| button.textContent = 'Copied!'; | ||
| setTimeout(() => (button.textContent = 'Copy'), 2000); |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clipboard API usage lacks error handling. If the clipboard write fails (e.g., due to browser permissions or HTTPS requirement), the promise rejection is not caught, which could lead to unhandled promise rejections. Consider adding a .catch() handler to provide user feedback when copying fails.
| setTimeout(() => (button.textContent = 'Copy'), 2000); | |
| setTimeout(() => (button.textContent = 'Copy'), 2000); | |
| }).catch(() => { | |
| button.textContent = 'Failed!'; | |
| setTimeout(() => (button.textContent = 'Copy'), 2000); |
| <pre><code> | ||
| function calculateTip(bill, percentage) { | ||
| return (bill * percentage) / 100; | ||
| } | ||
| </code></pre> |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code inside the <code> tag has inconsistent indentation. The opening line starts on line 35, but the function code on lines 36-38 has extra leading whitespace that will be copied when users click the copy button. Consider removing the extra indentation to provide cleaner copied code, or adjust the indentation to be consistent with typical JavaScript formatting.
| "devDependencies": { | ||
| "@honkit/honkit-plugin-ga": "^1.0.1", | ||
| "cz-conventional-changelog": "^3.3.0", | ||
| "cz-conventional-changelog": "^3.0.1", |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change downgrades cz-conventional-changelog from ^3.3.0 to ^3.0.1. Unless there's a specific reason for this downgrade (such as compatibility issues), it's generally better to keep dependencies at their latest compatible versions to benefit from bug fixes and improvements. Please verify if this downgrade is intentional.
| "cz-conventional-changelog": "^3.0.1", | |
| "cz-conventional-changelog": "^3.3.0", |
This pull request adds a “Copy” button to the code snippet section in the Tip Calculator example, allowing users to easily copy example code with one click.
Additionally, minor UI improvements have been made to enhance readability and visual separation.
Changes Made:
Added a Copy button with clipboard functionality.
Styled