I was looking for a way to quickly get interesting parts of a web page formatted to DokuWiki markup.
No menus and headers and footers or sidebars — just a clean selection on the page.
I solved it by translating from HTML to DokuWiki markup in the clipboard using two Linux utilities, xclip
xclip is a command line interface to X11 clipboard, Pandoc is universal markup converter — a work of art from professor of Philosophy John MacFarlane.
It can also convert to MediaWiki, TikiWiki, TWiki, Vimwiki, XWiki and ZimWiki.
xclip and pandoc can use stdin / stdout for piping. Converting the clipboard thus becomes stupid simple. A shell script with a Zenity confirm & verify dialog looks like this…
# Pipe clipboard to pandoc and pipe the DokuWiki markup back to clipboard
xclip -o -selection clipboard | pandoc -f html -t dokuwiki | xclip -selection clipboard
# Save first five non-blank lines from clipboard truncated to one hundred characters in the confirmation dialog
result=$(xclip -o -selection clipboard | tr -s '\n' '\n' | head -n 5 | cut -c -100 )
# Info box with saved preview of clipboard contents
zenity --info --title="HTML to Dokuwiki markup" --text="Clipboard preview: \n\n $result" --width=300 --height=100
To implement; (1) put the above code in a file clip-to-dokuwiki.sh
somewhere in your $PATH such as /home/user/.local/bin and (2) make executable by chmod u+x clip-to-dokuwiki.sh
Assign this script to a keyboard shortcut, why not Super-M for markup?
On xubuntu: Keyboard settings -> Application Shortcuts tab -> Add
Enter the full script path /home/user/.local/bin/clip-to-dokuwiki.sh and assign the keyboard shortcut.
* Select the text you want to capture on the page in browser.
* Right-click and choose “View Selection Source
”. Your selection opens up as HTML in the page source.
* Keyboard ctrl-C to copy, and then..
* super-M to execute script and convert clipboard to DokuWiki markup.
Last step, create your empty DokuWiki page and ctrl-v paste the markup.
* Select text in browser
* Right-click “View selection source”
* Ctrl-C, copy HTML-selection
* Super-M, or other keyboard shortcut assigned, to execute script
* Create empty DokuWiki Page
* Ctrl-V to paste DokuWiki markup
The workflow is minimal, wikiwiki and smooth, hope you find it just as powerful as I did, let me know if you need any help in getting it to work.
Also shared this on Medium https://link.medium.com/fGD3gnW3QV
Pandoc uses an intermediate representation format which produces a flawless conversion with headers, quotes, images and links.