dbunskoek
dbunskoek8mo ago

Is there a way to create a syntax

Is there a way to create a syntax highlighted code block that has copy-to-clipboard functionality with marimo?
7 Replies
dbunskoek
dbunskoekOP8mo ago
I'm currently leaning towards building this using the anywidget (https://docs.marimo.io/api/inputs/anywidget.html#marimo.ui.anywidget) approach, is that the right way to go?
Myles Scolnick
Myles Scolnick8mo ago
that would work. using some existing stuff, you can do markdown (mo.md) with code-fences ("``` python ) and then make a button to copy the code
dbunskoek
dbunskoekOP8mo ago
ah, that sounds like an easier approach, thanks! any pointers on how I would make that button in marimo? could I perhaps override / extend the current mo.md function for that? or is there a better way? I'm currently looking at the source code for mo.md, and it looks like I could use a custom pymdownx extension for this
Myles Scolnick
Myles Scolnick8mo ago
we don't have a copy-to-clipboard actually (maybe we should) we can either add that to mo.ui.code_editor or mo.download - if you submit a feature-request
dbunskoek
dbunskoekOP8mo ago
OK, thanks, I'll look into that! where should I create that feature-request? should it be a GitHub issue, and would it be helpful if I had a stab at an initial implementation myself?
Myles Scolnick
Myles Scolnick8mo ago
GitHub issue would be great. And we would really appreciate a contribution. I can always help out and point you in the right direction. The CodeEditor plugin is probably the easiest to contribute too to add a copy button
dbunskoek
dbunskoekOP8mo ago
yep, I thought so as well... I'm looking into that now, thanks!