Skip to content

Instantly share code, notes, and snippets.

@manuelp
Created December 16, 2016 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelp/ed152fefc666c6d1cec0884bb3a7cba7 to your computer and use it in GitHub Desktop.
Save manuelp/ed152fefc666c6d1cec0884bb3a7cba7 to your computer and use it in GitHub Desktop.
Markdown support for Emacs
;; ========== Markdown
(use-package markdown-mode
:ensure t
:config
(setq markdown-coding-system "utf-8")
(add-hook 'markdown-mode-hook 'turn-off-auto-fill)
(add-hook 'markdown-mode-hook 'toggle-word-wrap)
;; Source: https://gist.github.com/edavis10/6084120
(add-hook 'markdown-mode-hook
(lambda ()
;; Open org-mode style links, [[file:relative.md]]
(local-set-key (kbd "C-c C-o") 'org-open-at-point-global)))
:mode (("\\.md" . markdown-mode)
("\\.markdown" . markdown-mode))
:bind
(("C-c l" . markdown-follow-link-at-point)))
(use-package markdown-toc
:ensure t)
;; Automatic preview
;; Link: https://github.com/mola-T/flymd
(use-package flymd
:ensure t)
(defun markdown-to-html ()
"Compiles the current file to HTML using Pandoc."
(interactive)
(let ((output-dir (read-directory-name "Output directory: "))
(input-file (file-name-nondirectory buffer-file-name)))
(setq output-file (concat output-dir "/" (file-name-sans-extension input-file) ".html"))
(shell-command-on-region
(point-min) (point-max)
(concat "pandoc -f markdown -t html5 -Ss --toc --self-contained -c https://raw.githubusercontent.com/manuelp/pandoc-stylesheet/master/pub.css -o " output-file " " input-file))))
(defun markdown-to-pdf ()
"Compiles the current file to PDF using Pandoc."
(interactive)
(let ((output-dir (read-directory-name "Output directory: "))
(input-file (file-name-nondirectory buffer-file-name)))
(setq output-file (concat output-dir "/" (file-name-sans-extension input-file) ".pdf"))
(shell-command-on-region
(point-min) (point-max)
(concat "pandoc -f markdown -Ss --toc --chapters --number-sections --variable papersize:a4paper --variable documentclass:article --variable colorlinks:blue -o " output-file " " input-file))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment