Emacs Lisp: mark HTML on the web page and convert it quickly to Markdown format
Emacs Lisp: mark HTML on the web page and convert it quickly to Markdown format. This function needs your own customizations. You would mark the HTML on a web page within your browser. Then you run the Emacs Lisp function and the clipboard is converted into Markdown file. The file is opened for further editing and saved for future just as a note.
Customize the function to your own needs, for example, you should change the directory where files are stored. And you must have shell commands xclip
and pandoc
.
defun command-stream (command string &rest args)
(
(with-temp-bufferlet* ((process (apply 'start-process "PROCESS" (current-buffer) command args)))
(
(set-process-sentinel process #'ignore)string)
(process-send-string process
(process-send-eof process)
(process-send-eof process)
(while (accept-process-output process))
(buffer-string))))
defun rcd/timestamp ()
("%Y-%m-%d-%T"))
(format-time-string
defun clipboard-to-markdown-file ()
("This function helps to capture HTML from web pages into
files in Markown format. You would need to mark the parts of
the HTML page within your browser such as Iceweasel or
IceCat. Then you run this function in Emacs Lisp. It uses
`pandoc` and `xclip` shell commands to write Markdown
file. Finally it opens file for editing."
(interactive)let* ((markdown-dir "/home/data1/protected/Documents/HTML-Markdown/")
(".md"))
(filename (concat markdown-dir (rcd/timestamp) "xclip -t text/html -selection primary -out"))
(clipboard (shell-command-to-string "pandoc" clipboard "-r" "html" "-w" "commonmark")))
(markdown (command-stream
(string-to-file-force markdown filename) (find-file filename)))
Leave Your Comment or Contact GNU.Support
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