How to copy HTML snippets from Internet browser to Markdown files
This short article will explain you how to copy the HTML snippets directly from your Internet browser to Markdown files. In case of any troubles, contact GNU.Support and we will help you set this powerful system for static website publishers and Markdown users. I wish to share how I am copying the HTML snippets from web pages and converting them into markdown files on the hard disk directly.
I wish to share how I am copying the HTML snippets from web pages and converting them into markdown files on the hard disk directly.
Often I write some test on third party websites, and often there is text that was authored by other people and is permissive to be copied and distributed.
Yet, who wants all that HTML?
First I was searching for the Firefox extension that may copy the HTML to markdown, but what I found is just the one which does not copy all the HTML.
And then I found the answer on StackExchange which refers directly to pandoc’s command:
xclip -o -selection clipboard -t text/html | pandoc -r html -w markdown
I am using so much keyboard input, as I am user of the tiling window manager StumpWM that gives me good control over windows.
So I have modified one key for the window manager to run the command, to convert the X clipboard content with HTML data (it is not to work on Windows) to markdown files.
So, I made the configuration like:
"M") "exec save-html-as-markdown")(define-key *root-map* (kbd
Which means, when I press the keys C-t followed by upcase M, the program save-html-as-markdown is to be run in background.
Small program in background is peace of Lisp code, that defines the directory where such snippets of HTML, converted to markdown, are to be saved and runs the pandoc command.
In this example, I am using CLISP as Lisp version but it really can be easily adapted to any programming language that is to save the output of the pandoc command to a file. I am saving it into files named after date and time.
#!/home/data1/protected/bin/lisp;;;; released to public domain defun timestamp-filename nil (multiple-value-bind (second minute hour date month year day-of-week dst-p tz) (get-decoded-time) (format nil "~d-~2,'0d-~2,'0d-~2,'0d:~2,'0d:~2,'0d" ( year month date hour minutesecond ))) defparameter *html-to-markdown-dir* "/home/data1/protected/Documents/HTML-Markdown/") ( let* ((filename (concatenate 'string (timestamp-filename) ".md")) ("xclip -t text/html -selection primary -out | pandoc -r html -w commonmark" :output :string)) (markdown (uiop:run-program concatenate 'string *html-to-markdown-dir* filename))) (output ( (alexandria:write-string-into-file markdown output)concatenate 'string "emacs-client-x " output))) (uiop:run-program (
I am sure somebody can write much easier shorter Bash script or Python, whatever similar script to give the same result.
It could be as simple as:
#!/bin/bash FILE=`/bin/date -Iseconds`.md xclip -t text/html -selection primary -out | pandoc -r html -w commonmark > $FILE emacs $FILE
In my version, after the program execution, GNU Emacs editor is firing up the file that was saved as
for example, and I may modify the file and also make sure that file does exist.
This way, anything that I write on someone’s blog or if I find HTML content that I wish to reuse, I simply mark, copy and press keys C-t M that creates the markdown file on the disk.
Other window managers may do the same if they allow the keyboard customization.
Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know