add copy button for lstlistings#2629
Conversation
|
I had marked this PR as a draft only because I wasn't sure where the CSS and JS code for the copy button of lstlistings should go... Nothing has changed but I will now mark it as ready for review - just bear with me that the above will require some input and guidance from your side. |
- fix 'Illegal character in scheme data: “<” is not allowed'
|
Oooh, I like it! I'm gonna want to use it myself! But I'm a little concerned about naming & packaging. For those that use listing, but not the clipboard, the CSS load is a bit heavy. It would probably be good to separate that out and name both files Kinda long. Or possibly even just |
|
Oh, and whatever names, they'll need to be added to the MANIFEST file |
|
Very quick comment, because I was looking into this just today as I'd personally like to have both copy & dowload buttons... The clipboard bits can be implemented directly into an onclick handler as url=event.target.nextElementSibling.href;clipboard.writeText(atob(subtring(url.substring(url.indexOf(',')+1))))assuming you add the button right in front of the existing download link (code may be slightly wrong). That's more robust than hiding the line numbers, selecting the text etc. I also wanted to point out that the download button has its uses, e.g. when the file name is known (because it was inserted by reading a file, or by specifying the |
This PR aims to address #2588.
The
lstlisting.jsadds a hook to replace all download links in HTML documents by a download button after the document has been loaded.Following @dginev's encouragement, I polished my JavaScript and created my own icons to avoid any copyright issues. All SVG icons are in the CSS in order to minimize the number of files, while maintaining customizability.
I marked the PR as a draft because I'm struggling with
Currently, I pass a JS file to
LaTeXMLwith--javascript=<custom.js>, which includes the code fromlstlisting.jsand the resulting buttons work as expected.I'm looking forward to your feedback/guidance on this - or watch what changes you make to the code 😄.