Created
January 19, 2015 18:37
-
-
Save jonEbird/c5b79f0756b00f3bf193 to your computer and use it in GitHub Desktop.
README Preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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