JetBrains IDEs platform plugin that copies selection, including syntax highlighting, formatting, font and background, as plain text containing inline-styled HTML markup.
For when you want to embed your code as you see it, not as some random dumb syntax highlighter will colorize it.
It copies selection as both text/plain
and text/html
, so you can paste the same clipboard content in plain text editor,
like your blog editor, and in places that support rich text pasting, like Google Slides, Keynote or MS Word.
In Markdown, it only works when HTML blocks are supported and style
attributes are not ignored.
So it won't work in GitHub Flavored Markdown files, but will work in eg. Medium or Ghost blog posts.
So this code...
... becomes this plain text in your clipboard:
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body><pre style="background-color:#212121;color:#f5f5f5;font-family:'Roboto Mono';font-size:9.8pt;"><span style="color:#e91e63;">override fun </span><span style="color:#8bc34a;">actionPerformed</span>(<span style="color:#ff9800;">event</span>: <span style="color:#00bcd4;">AnActionEvent</span>) {<br>    <span style="color:#00bcd4;">ActionManager</span>.getInstance().getAction(<span style="color:#ff5722;">IdeActions</span>.<span style="color:#9575cd;font-style:italic;">ACTION_EDITOR_COPY</span>).actionPerformed(<span style="color:#ff9800;">event</span>)<br><br>    <span style="color:#e91e63;">val </span>copyPasteManager <span style="color:#e91e63;">= </span><span style="color:#00bcd4;">CopyPasteManager</span>.getInstance()<br><br>    <span style="color:#e91e63;">val </span>textBlockTransferable <span style="color:#e91e63;">= </span>copyPasteManager.<span style="color:#9575cd;font-style:italic;">allContents<br></span><span style="color:#9575cd;font-style:italic;">        </span>.<span style="font-style:italic;">filterIsInstance</span><span style="color:#e91e63;"><</span><span style="color:#00bcd4;">TextBlockTransferable</span><span style="color:#e91e63;">></span>()<br>        .<span style="font-style:italic;">firstOrNull</span>() <span style="color:#e91e63;">?</span>: <span style="color:#e91e63;">return<br></span><span style="color:#e91e63;"><br></span><span style="color:#e91e63;">    val </span>dataFlavor <span style="color:#e91e63;">= </span>textBlockTransferable.<span style="color:#9575cd;font-style:italic;">transferDataFlavors<br></span><span style="color:#9575cd;font-style:italic;">        </span>.<span style="font-style:italic;">firstOrNull </span><span style="font-weight:bold;">{ it</span>.isMimeTypeEqual(<span style="color:#fff176;">"text/html"</span>) <span style="font-weight:bold;">} </span><span style="color:#e91e63;">?</span>: <span style="color:#e91e63;">return<br></span><span style="color:#e91e63;"><br></span><span style="color:#e91e63;">    </span>dataFlavor.getReaderForText(textBlockTransferable).<span style="font-style:italic;">useLines </span><span style="font-weight:bold;">{ </span><span style="color:#ff9800;">lines </span><span style="font-weight:bold;">-><br></span><span style="font-weight:bold;">        </span>copyPasteManager.setContents(<span style="color:#00bcd4;">TextTransferable</span>(<span style="color:#ff9800;">lines</span>.<span style="font-style:italic;">joinToString</span>(<span style="color:#03a9f4;">separator = </span><span style="color:#fff176;">""</span>)))<br>    <span style="font-weight:bold;">}<br></span>}</pre></body></html>
After installing, when editor has selection the Copy as HTML
action will be available in Edit and popup menu with shortcut of Shift+Cmd+H
(or Shift+Ctrl+H
on Windows and Linux).
This project is licensed under the MIT License. See the LICENSE file for details.