Skip to content

Instantly share code, notes, and snippets.

@jonEbird
Created June 12, 2014 23:53
Show Gist options
  • Save jonEbird/22bb0520cce8c2ea3c1f to your computer and use it in GitHub Desktop.
Save jonEbird/22bb0520cce8c2ea3c1f to your computer and use it in GitHub Desktop.
Preview the Github Markdown to HTML convertion before committing. Bound to F12 in markdown-mode.
;; Markdown preview helper
;; ------------------------------
(defun jsm/markdown-preview ()
"Preview the markdown file in a new browser tab"
(interactive)
(let ((my-filename (buffer-file-name))
(html-filename (format "%s.html" (file-name-base (buffer-file-name)))))
(shell-command (format "pandoc -f markdown_github -t html -o %s %s" html-filename my-filename) nil nil)
(browse-url (concat "file://" (file-name-directory (buffer-file-name)) html-filename))))
(define-key markdown-mode-map (kbd "<f12>") 'jsm/markdown-preview)
@jonEbird
Copy link
Author

Requires installation of the pandoc utility. Available on Fedora systems via yum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment