Skip to content

Instantly share code, notes, and snippets.

@jonEbird
Created January 19, 2015 18:37
Show Gist options
  • Save jonEbird/c5b79f0756b00f3bf193 to your computer and use it in GitHub Desktop.
Save jonEbird/c5b79f0756b00f3bf193 to your computer and use it in GitHub Desktop.
README Preview
;; README preview helper thanks to pandoc
;; ------------------------------
(defun readme-preview ()
"Preview the README rendered to html in a browser tab via pandoc"
(interactive)
(let* ((html-filename (format "%s.html" (file-name-base buffer-file-name)))
(input-format (cond
((derived-mode-p 'rst-mode) "rst")
((derived-mode-p 'markdown-mode) "markdown_github")))
(cmd (format "pandoc -f %s -t html -o %s %s"
input-format html-filename buffer-file-name)))
(shell-command cmd nil nil)
(browse-url (concat "file://" (file-name-directory buffer-file-name) html-filename))))
;; Assign F12 to render README preview for select modes
(dolist (hook '(markdown-mode-hook rst-mode-hook))
(add-hook hook
'(lambda () (local-set-key (kbd "<f12>") 'readme-preview))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment