-
Notifications
You must be signed in to change notification settings - Fork 71
Paste formatted text custom tool
Instead of this custom tool, you can install the pastefromhtml plugin which doesn't depend on Pandoc and is able to paste images!
https://github.com/cetinkaya/pastefromhtml
Zim doesn't support pasting formatted text from other applications at the moment.
As a workaround, we can use Pandoc to convert the clipboard content to Zim's wiki syntax and insert it in the active note with a Custom Tool, which can be bound to a Key Binding like Ctrl+Shift+V
- In the menu bar, click Tools → Custom Tools → the
[+]
on the right - Fill the dialog like this:
Edit Custom Tool | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Just install the pandoc
package with your distro's package manager. Make sure the xclip
command is available on your system as well.
# Debian, Ubuntu, etc.
$ sudo apt install pandoc xclip
# Arch, Manjaro, etc.
$ sudo pacman -S pandoc xclip
Pandoc is available in winget, Scoop and Chocolatey:
# winget
> winget install pandoc
# Scoop
> scoop install pandoc
# Chocolatey
> choco install pandoc
Otherwise, you can install Pandoc by following the instructions on the website: https://pandoc.org/installing.html
Older instructions with a html-to-zim.ps1
script
Then, somewhere on your PC, create a file html-to-zim.ps1
with this code in it:
$ofs = "`n"
$clipboard = Get-Clipboard -TextFormatType Html
$html_fragment = ("$clipboard" -split '<!--StartFragment-->|<!--EndFragment-->')[1]
$html_fragment | pandoc --from html --to zimwiki
If it is the first time you're running PowerShell scripts on your system, you might need to change the execution policy by opening a Windows PowerShell session and running
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
After having Pandoc installed and PowerShell configured to allow running arbitrary scripts, this Custom Tool's command should now be able to run.
It's probably possible to reduce this script to a one-liner. That would simplify the setup on Windows. (DONE)
- Open the Preferences window (Edit → Preferences on the menu bar)
- Go to the Key bindings tab
- There is an action for the Custom Tool you just created.
It's probably the 2nd or 3rd one in the list and the name might look like
<Actions>/custom_tools/paste from html-usercreated
- Double click the Key Binding cell (it probably says "Disabled")
- Press Ctrl+Shift+V
- Click OK
Copy some formatted text from Writer/Word or the web, then jump back to Zim and try pasting it with either Tools → Paste from HTML on the menubar, the toolbar button or Ctrl+Shift+V.
The clipboard was converted to Zim's wiki syntax and inserted in the cursor's position!
Now press Ctrl+R for Zim to redisplay it as formatted text.