I want to be able to highlight a section of a web page and copy it to the clipboard then save it to my local disk as markdown. I need an efficient way to do that.
My current cumbersome method is:
cd
to the directory where I saved the HTMLpandoc -s -r html /home/me/a/b/mydoc.html -o /home/me/a/b/mydoc.md
Obviously, I need a better method! Any suggestions?
With a recent version of xclip
(the -t
option was added in 2010 but not released yet AFAICT, so you'd need to get it from subversion, or use the one packaged in Debian).
xclip -o -selection clipboard -t text/html | pandoc -r html -w markdown
And if you want to make that back into the clipboard:
xclip -o -selection clipboard -t text/html |
pandoc -r html -w markdown |
xclip -i -selection clipboard
Which you can do in a loop with:
while :; do
xclip -o -selection clipboard -t text/html |
pandoc -r html -w markdown |
xclip -i -selection clipboard -quiet
done
The second xclip
, with -quiet
will block until something else claims the CLIPBOARD selection, that is until you select something else somewhere.
That way, you can copy back and forth between your browser and whatever you're pasting the markdown in.
@tink also has a useful link to a similar question on StackOverflow where you can find how to implement it in python.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments