Skip to content

Adding a CopyButton feature#537

Open
yufi16 wants to merge 2 commits intoflatcar:mainfrom
yufi16:styling-work
Open

Adding a CopyButton feature#537
yufi16 wants to merge 2 commits intoflatcar:mainfrom
yufi16:styling-work

Conversation

@yufi16
Copy link
Copy Markdown

@yufi16 yufi16 commented Mar 5, 2026

What this PR does / why we need it:

Introducing a Copy button feature to quickly copy code snippets, reducing friction and saving time.

Which issue(s) this PR fixes:

#2022 -> flatcar/Flatcar#2022

Does this PR introduce a user-facing change?

Enhancing code blocks with distinct background, improving readability and visual clarity.

Special Notes for your Reviewer:

Incorporated suggested changes.

Copy link
Copy Markdown
Collaborator

@tormath1 tormath1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, while I'm not a front-end developer, I'll delegate this PR review to @ervcz :)

Comment thread .idea/.gitignore Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid adding the .idea folder. We can .idea to the main .gitignore file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing @tormath1
With a couple more changes, will stash them before opening the PR for review.

@John15321
Copy link
Copy Markdown
Member

Linking it for visibility 😊 flatcar/Flatcar#2022

@sayanchowdhury
Copy link
Copy Markdown
Member

Thanks a lot for the PR!

The implementation needs to change a bit, currently the copy button is rendered outside of the codeblock - which does not look good in UI terms.

It would be better to use a font-awesome icon and place it within.

Other thing is we use pygments, but you can switch over to use Hugo's highlight which give much more better themes for the code block.

Comment thread themes/flatcar/static/js/copy.js Outdated
@yufi16 yufi16 force-pushed the styling-work branch 6 times, most recently from 6ba5054 to 63efd51 Compare March 18, 2026 09:21
@yufi16 yufi16 changed the title adding a copy button | scss styling Adding a Copy button | Scss styling Mar 18, 2026
@yufi16 yufi16 changed the title Adding a Copy button | Scss styling Adding a Copy button | Scss Styling Mar 18, 2026
@yufi16 yufi16 changed the title Adding a Copy button | Scss Styling Adding a Copy button | scss styling Mar 18, 2026
@yufi16 yufi16 changed the title Adding a Copy button | scss styling Adding a Copy button | Scss styling Mar 18, 2026
@yufi16 yufi16 marked this pull request as ready for review March 18, 2026 12:25
@yufi16 yufi16 requested a review from a team as a code owner March 18, 2026 12:25
@John15321
Copy link
Copy Markdown
Member

Could you please remove the .idea folder from Git?

@John15321
Copy link
Copy Markdown
Member

John15321 commented Mar 18, 2026

Hmm (when running locally), when I use the copy button it adds new lines to each of the lines after pasting it in:
image

http://localhost:1313/docs/latest/installing/vms/vagrant/#:~:text=List%20the%20status%20of%20the%20running%20machines%3A

@yufi16
Copy link
Copy Markdown
Author

yufi16 commented Mar 18, 2026

Hmm (when running locally), when I use the copy button it adds new lines to each of the lines after pasting it in: image

http://localhost:1313/docs/latest/installing/vms/vagrant/#:~:text=List%20the%20status%20of%20the%20running%20machines%3A

Thanks for investigating, looking into this!

@yufi16 yufi16 force-pushed the styling-work branch 5 times, most recently from 75b28f1 to 9d34850 Compare March 19, 2026 03:49
@yufi16 yufi16 closed this Mar 19, 2026
@yufi16 yufi16 reopened this Mar 19, 2026
@yufi16 yufi16 changed the title Adding a Copy button | Scss styling Adding a CopyButton feature Mar 19, 2026
@sayanchowdhury
Copy link
Copy Markdown
Member

Hmm (when running locally), when I use the copy button it adds new lines to each of the lines after pasting it in: image

http://localhost:1313/docs/latest/installing/vms/vagrant#:~:text=List the status of the running machines%3A

I see that the innerText that you are using is returning a \n in the end - you could switch to textContent and check. For this example textContent returns me without the trailing newline.

or better just use trim() or trimEnd() to stay on the safer side.

Comment thread static/js/common.js
Comment thread static/js/copybutton.js Outdated
Comment thread themes/flatcar/assets/js/common.js Outdated
Comment thread themes/flatcar/assets/scss/_styles.scss Outdated
Comment thread themes/flatcar/assets/scss/_styles.scss Outdated
Comment thread themes/flatcar/layouts/docs/baseof.html Outdated
Comment thread themes/flatcar/layouts/docs/baseof.html Outdated
Comment thread .gitignore
Comment thread themes/flatcar/assets/js/common.js Outdated
Comment thread themes/flatcar/assets/scss/_styles.scss
Copy link
Copy Markdown
Member

@sayanchowdhury sayanchowdhury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped a few comments - it should look exactly how it looks but there is some redundant code which needs to be removed.

@yufi16
Copy link
Copy Markdown
Author

yufi16 commented Mar 27, 2026

Sure, on it!

@yufi16 yufi16 force-pushed the styling-work branch 9 times, most recently from d1ed56f to 5daf7f0 Compare March 31, 2026 08:25
@sayanchowdhury
Copy link
Copy Markdown
Member

This would require to pull #548

@ervcz this PR would also require your review when you have spare cycles

@ervcz
Copy link
Copy Markdown
Contributor

ervcz commented Apr 23, 2026

Hello @yufi16, @sayanchowdhury! Sorry for the late response.

Please use the existing SCSS variables. E.g. $flatcar-blue for #08a2af, $gray-100 for #f8f9fa, etc. These are exact matches already defined in _custom.scss and Bootstraps variables.

Can you please check if "Fira Code" is properly loading? That is a custom font that is not installed on most of devices.

Signed-off-by: yussaffi <yufi.alam@outlook.com>
height: 2px;
position: absolute;
top: 0%;
top: 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use measurement units? It may still be correct without them, but it is a good practice to indicate them.

top: 0;
left: 0;
width: 100%;
width: 100;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

}

&.copied {
background: $flatcar-blue; /* cyan-blue feedback */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment can be removed.

border-radius: 6px;
display: block;
overflow-x: auto;
font-family: "Fira Code", monospace;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed we already load a monospace font family. Could we use $font-family-monospace instead (- that should include it)? Perhaps the difference doesn't make worth loading a new font family.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what we have already is called overpass mono

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Overpass+Mono:wght@300;400;600;700&family=Overpass:ital,wght@0,100;0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet" media="print" onload="this.media='all'"/>

<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&display=swap" rel="stylesheet">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If overpass mono is similar enough to fira code, I would suggest to drop fira code

@yufi16
Copy link
Copy Markdown
Author

yufi16 commented Apr 28, 2026

Sure thing, On it!

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.

6 participants