-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-htmlize.el
47 lines (43 loc) · 1.53 KB
/
my-htmlize.el
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
;;; my-htmlize --- htmlize tweaks
;;
;; Copyright (C) 2014 Alex Bennée
;;
;; Author: Alex Bennée <[email protected]>
;;
;;; Commentary:
;;
;; I don't use this so much now but it is useful for posting codedumps
;; in a formatted way
;;
;;; Code
(require 'use-package)
(require 'my-web)
(use-package htmlize
:ensure t
:commands (htmlize-faces-in-buffer htmlize-make-face-map htmlize-css-specs htmlize-region-for-paste)
:config
(setq htmlize-output-type 'inline-css))
;; From http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/
(defun my-htmlize-region (beg end)
"Htmlize region and put into <pre> tag style that is left in <body> tag
plus add font-size: 8pt"
(interactive "r")
(let* ((buffer-faces (htmlize-faces-in-buffer))
(face-map (htmlize-make-face-map (adjoin 'default buffer-faces)))
(pre-tag (format
"<pre style=\"%s font-size: 8pt\">"
(mapconcat #'identity (htmlize-css-specs
(gethash 'default face-map)) " ")))
(htmlized-reg (htmlize-region-for-paste beg end)))
(switch-to-buffer-other-window "*htmlized output*")
; clear buffer
(kill-region (point-min) (point-max))
; set mode to have syntax highlighting
(web-mode)
(save-excursion
(insert htmlized-reg))
(while (re-search-forward "<pre>" nil t)
(replace-match pre-tag nil nil))
(goto-char (point-min))))
(provide 'my-htmlize)
;;; my-htmlize.el ends here