summaryrefslogtreecommitdiff
path: root/modules/markdown-config.el
blob: e25dfbf3084bd242fd1b0142e09734df82d96241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;; markdown-config --- Settings for Editing Markdown -*- lexical-binding: t; -*-
;; author Craig Jennings <c@cjennings.net>

;;; Commentary:

;;; Code:

;;;; ------------------------- Markdown-Mode -------------------------

(use-package markdown-mode
  :mode (("README\\.md\\'" . gfm-mode)
		 ("\\.md\\'"       . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :bind (:map markdown-mode-map
			  ("<f2>" . markdown-preview)) ;; use same key as compile for consistency
  :init (setq markdown-command "multimarkdown"))

;;;; ------------------------- Impatient-Mode ------------------------

;; allows for live previews of your html
;; see: https://github.com/skeeto/impatient-mode
(use-package impatient-mode
  :defer t
  :config
  (setq imp-set-user-filter 'markdown-html))

;;;; --------------------- WIP: Markdown-Preview ---------------------

;; the filter to apply to markdown before impatient-mode pushes it to the server
(defun markdown-preview ()
  (interactive)
  (httpd-start)
  (impatient-mode 1)
  (setq imp-user-filter #'cj/markdown-html)
  (cl-incf imp-last-state)
  (imp--notify-clients)
  ;;  (browse-url-generic-function 'browse-url-xdg-open)
  (browse-url-generic "https://localhost:8080/imp" 1))

(defun cj/markdown-html (buffer)
  (princ (with-current-buffer buffer
		   (format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s  </xmp><script src=\"http://ndossougbe.github.io/strapdown/dist/strapdown.js\"></script></html>"
				   (buffer-substring-no-properties (point-min) (point-max))))
		 (current-buffer)))

(provide 'markdown-config)
;;; markdown-config.el ends here