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

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.

First to do is to mark the HTML page inside of your browser

In a second you should get the converted HTML to Markdown format temporary file.

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-buffer
        (let* ((process (apply 'start-process "PROCESS" (current-buffer) command args)))
          (set-process-sentinel process #'ignore)
          (process-send-string process string)
          (process-send-eof process)
          (process-send-eof process)
          (while (accept-process-output process))
          (buffer-string))))

    (defun rcd/timestamp ()
      (format-time-string "%Y-%m-%d-%T"))

    (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/")
         (filename (concat markdown-dir (rcd/timestamp) ".md"))
         (clipboard (shell-command-to-string "xclip -t text/html -selection primary -out"))
         (markdown (command-stream "pandoc" clipboard "-r" "html" "-w" "commonmark")))
        (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


Full name:


E-mail:


Message: