-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
feat: add copy button for markdown code blocks #2799
Conversation
Try this Pull Request!Open Julia and type: julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/chayandatta/Pluto.jl", rev="cd/copy-button")
julia> using Pluto |
Heyyy that's cool! Could you reupload the screenshots? The URLs are from a private repo |
I would like to also use this functionality in more places!
Do you think it is possible to move this functionality to the RawHTMLContainer component? You could take a look at where we call Als try to extract this functionality into a new function, just like |
Hi, I've moved the code inside RawHTMLContainer and extracted the functionality into a new function.
As far I can understand, where and |
Thanks for taking a look again! This is not exactly what I meant. 🙈 Instead of using regex to find the code blocks, and then a preact element for the button, consider using In CellOutput.js, add this block: // EXISTING:
// Apply syntax highlighting
try {
... highlight ...
} catch ... {}
// NEW:
// Find code blocks and add a copy button:
try {
if (container.firstElementChild?.matches("div.markdown")) {
container.querySelectorAll("pre > code").forEach((code_element) => {
const pre = code_element.parentElement
add_code_copy_button(pre)
})
}
} catch (err) {
console.warn("Adding markdown code copy button failed", err)
} Then the |
It's true that |
Kapture.2024-03-13.at.17.08.33.mp4 |
fixes: #2668
Thanks @pankgeorg for all the help