-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,5 +56,26 @@ function calculate() { | |||||||||||
| resultsDiv.style.background = '#f1f5f9'; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| document.querySelectorAll('pre > code').forEach(codeBlock => { | ||||||||||||
| const button = document.createElement('button'); | ||||||||||||
| button.className = 'copy-btn'; | ||||||||||||
| button.textContent = 'Copy'; | ||||||||||||
|
|
||||||||||||
| const pre = codeBlock.parentNode; | ||||||||||||
| const wrapper = document.createElement('div'); | ||||||||||||
| wrapper.className = 'code-block'; | ||||||||||||
| pre.parentNode.insertBefore(wrapper, pre); | ||||||||||||
| wrapper.appendChild(pre); | ||||||||||||
| wrapper.appendChild(button); | ||||||||||||
|
|
||||||||||||
| button.addEventListener('click', () => { | ||||||||||||
| const text = codeBlock.textContent; | ||||||||||||
| navigator.clipboard.writeText(text).then(() => { | ||||||||||||
| button.textContent = 'Copied!'; | ||||||||||||
| setTimeout(() => (button.textContent = 'Copy'), 2000); | ||||||||||||
|
||||||||||||
| setTimeout(() => (button.textContent = 'Copy'), 2000); | |
| setTimeout(() => (button.textContent = 'Copy'), 2000); | |
| }).catch(() => { | |
| button.textContent = 'Failed!'; | |
| setTimeout(() => (button.textContent = 'Copy'), 2000); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,43 @@ input[type="number"] { | |
| border: 1px solid #ddd; | ||
| } | ||
|
|
||
| .code-block { | ||
| margin-top: 20px; | ||
| } | ||
|
Comment on lines
+36
to
+38
|
||
|
|
||
| .code-block pre { | ||
| background-color: #f5f5f5; | ||
| border: 1px solid #ddd; | ||
| border-radius: 8px; | ||
| padding: 12px; | ||
| overflow-x: auto; | ||
| font-size: 14px; | ||
| line-height: 1.4; | ||
| } | ||
|
|
||
| .copy-btn { | ||
| position: absolute; | ||
| top: 8px; | ||
| right: 8px; | ||
| background: #4CAF50; | ||
| color: white; | ||
| border: none; | ||
| padding: 5px 10px; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| font-size: 14px; | ||
| transition: background 0.3s; | ||
| } | ||
|
|
||
| .copy-btn:hover { | ||
| background: #45a049; | ||
| } | ||
|
|
||
| .code-block { | ||
| position: relative; | ||
| } | ||
|
|
||
|
|
||
| .tips { | ||
| display: flex; | ||
| gap: 8px; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,11 @@ | |||||
| "main": "index.js", | ||||||
| "devDependencies": { | ||||||
| "@honkit/honkit-plugin-ga": "^1.0.1", | ||||||
| "cz-conventional-changelog": "^3.3.0", | ||||||
| "cz-conventional-changelog": "^3.0.1", | ||||||
|
||||||
| "cz-conventional-changelog": "^3.0.1", | |
| "cz-conventional-changelog": "^3.3.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", |
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.
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.