Skip to content

Copy to clipboard for lstlisting #2588

@evoludolab

Description

@evoludolab

When translating code listings to html, LaTeXML conveniently creates download links for code snippets. It would be even more user-friendly if this could be changed to a copy-to-clipboard-button.

I started playing around with LaTeXML-block-xhtml.xsl and made some progress but it's far from satisfactory... too big a hack to warrant a PR. More specifically, I started by replacing line 153 in LaTeXML-block-xhtml.xsl with

<xsl:element name="button" namespace="{$html_ns}">
    <xsl:attribute name="onclick">toClipboard(this.parentNode.parentNode)</xsl:attribute>
    <xsl:text>📋</xsl:text>
</xsl:element>

However, I would be happy to continue giving this a try if you were willing to give me some directions. More specifically, the issues I ran into were:

  • is this the right approach to begin with?
  • the clipboard icon is ugly and doesn't scale. An icon like GitHub uses above would be way nicer. Create copy icon and where to place it?
  • the custom javascript code for toClipboard (or similarly named) method needs to live somewhere. Create javascript code for copying and where to place it?
  • the argument this.parentNode.parentNode to toClipboard works but is ugly and so I expect that I am missing something...
  • make this configurable?

Any help and pointers are much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions