Site icon d3v.one

A VSCode extension to paste different clipboard formats

Today a short blog post about a Visual Studio Code extension I created a week ago. VSCode, as you might know, is a very popular code editor created and maintained by Microsoft and available for Windows, Linux, and macOS. The Stack Overflow Developer Survey 2019 now lists it as the most popular development environment used by 50.1% of the respondents, followed by Visual Studio with 31.5% and Notepad++ with 30.5%.

This extension implements a Paste Special function to paste clipboard content in different available formats. While Electron, the software base of VSCode, makes it possible to access at least text, HTML, RTF, and images as clipboard data, VSCode does not support that functionality in the editor. Unfortunately, it is also not possible to directly access the Electron API within a VSCode extension.

One has to take the long way. The extension uses platform-dependent native code modules that create information about the accessible clipboard formats using the JSON data format. Starting the code module as a child process without command line parameters lists all the available clipboard formats. When using the id of a specific clipboard format as a command line parameter, the clipboard data is returned.

As of now, only Windows and Linux are supported. When using macOS only text is available.

Supported formats for Windows are

Supported formats for Linux are

The extension can be installed from the Visual Studio Marketplace. Additional up-to-date information is available in the Readme.

The full source code of the extension is available via GitHub.

Quick tip: Transferring code snippets to a web page

When you copy text with syntax highlighting from the VSCode editor window to the clipboard, it is also copied in HTML format. So if you want to post syntax-highlighted code snippets to your web page, just copy and paste them with the Paste Special function into a new editor tab. From there you can use them directly on your web page, preserving all the fonts, formats and colors visible in the original editor window.

Where to go from here

Visual Studio Code: Your First Extension
Windows Dev Center: Clipboard
Clipboards: GTK+ 3 Reference Manual

Exit mobile version