DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:copy2clipboard

copy2clipboard Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" yes
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Add a clipboard button to <code> and <file> blocks that copies text to the clipboard

Last updated on
2023-04-17
Provides
Action
Repository
Source

Example/Usage

  1. Install the plugin
  2. Enjoy!

Once installed, it will automatically add a «copy to clipboard» button to every <code> or <file> code block as shown on the screenshot below. Actually, on desktop browser, buttons become visible only when mouse cursor enters the <code> or <file> region. On mobile browsers, the buttons are always visible.

Description

This extension add a clipboard button to <code> and <file> blocks that copies text to the clipboard

This is already done by other extensions, copycode and codeclipboard. However, it has the following advantages over the other extensions (being horribly partial here ;-)):

  1. made of pure javascript, there is no PHP requirement, no DokuWiki requirement. It will work on any DokuWiki version, with any PHP version,
  2. It uses a relatively new but stable javacript API, so it should work for years before it becomes incompatible with navigators,
    • Thus, as far as I can see, there will be no need to update this extension in the next millenia,
  3. It correctly copies codes formatted by geshi1). if you encounter the dreaded “Unrecognized character \xC2” error when you copy code to perl or python, manually or with other extensions, then copy2clipboard is the extension you need,
  4. It makes sure line endings are adapted to the os the navigator is running on. This eliminates powershell bug 496 and 3816 where lines are pasted in reverse order.
  5. It has no known bugs, yet.2)

Installation

Install the plugin using the Extensions Manager Plugin and the download URL above, which points to latest version of the plugin. Refer to Plugins on how to install plugins manually.

This plugin does not require any DokuWiki or PHP component. As it is made of pure javascript, it should work with any DokuWiki version.

Browser compatibility

Copy2clipboard is javascript only and requires that your browser supports writing text to the clipboard via the clipboard API. As of 2021, it seems to me that this is a not so old feature. Check the Clipboard Browser compatibility table on MDN for the major browser compatibility status. If you can't use your browser, either update your browser, use another extension (copycode and codeclipboard for example), or send a simple fix as a PR on github.

Configuration and Settings

There is nothing to configure. If you want that this plugin uses your language, please add a translation on https://translate.dokuwiki.org/plugin/copy2clipboard.

Change Log

Known Bugs and Issues

  • lone NO-BREAK SPACEs, (aka NBSP, aka U+00A0) on a line by themselves are not copied to the clipboard.
    • This is not a bug but a feature. A lone NBSP almost never happens intentionally in a source code, so this will virtually break no code. On the other hand, geshi which is used by DokuWiki adds it to every empty lines, making empty lines non empty. Moreover, U+00A0 is not a white space, and it causes syntax error in programming languages, or formatted text file such as YAML or LDIF. The benefit of removing this character is much greater than the drawback of keeping it.

Issues, bug, suggestions should only be discussed on github issues page.

Please note that issues relating to browser compatibility will not be fixed (by the author).

FAQ

Discussion

Please, use github issue page so this page stays as clear and simple as possible.

1)
This is the library component used by DokuWiki to highlight syntax
2)
This is the kind of statement that can't stand long…
plugin/copy2clipboard.txt · Last modified: 2024-03-04 17:42 by schplurtz

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki