diff options
| -rw-r--r-- | lisp/ravi-init-org.el | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/ravi-init-org.el b/lisp/ravi-init-org.el index 1b008a1..c4c3585 100644 --- a/lisp/ravi-init-org.el +++ b/lisp/ravi-init-org.el @@ -90,6 +90,32 @@ When nil, use the default face background.") (setq org-modules '(ol-bbdb ol-bookmark ol-git-link ol-info ol-man org-id)) (setq org-use-speed-commands t) + ;; Respect theme for code block output if enabled + ;; https://emacs.stackexchange.com/questions/3374/set-the-background-of-org-exported-code-blocks-according-to-theme + ;; Code above was modified to + ;; - use hexadecimal color values to avoid color names + ;; - modify org-html-head-extra only if colors were not already present; otherwise + ;; we end up appending to it on every export + (defvar ravi/org-html-code-block-parameter-set nil + "Set foreground and background for code blocks according to theme") + (defun ravi/org-inline-css-hook (exporter) + "Insert custom inline css to automatically set the +background of code according to theme" + (when (and (eq exporter 'html) + ;; To do: only if htmlize is used + ravi/org-html-code-block-parameter-set) + (let* ((converter (lambda (x) (apply #'color-rgb-to-hex + (flatten-list (list (color-name-to-rgb x) 2))))) + (pre-bg (funcall converter (face-background 'default))) + (pre-fg (funcall converter (face-foreground 'default))) + (extra (format "<style type=\"text/css\">\n pre.src {background-color: %s; color: %s;}</style>\n" + pre-bg pre-fg))) + (unless (and org-html-head-extra + (string-match (regexp-quote extra) org-html-head-extra)) + (set (make-local-variable 'org-html-head-extra) + (concat org-html-head-extra extra)))))) + (add-hook 'org-export-before-processing-hook 'ravi/org-inline-css-hook) + (defun ravi/org-color-customization () "Color customization for org mode" (setq ravi/org-html-code-block-parameter-set t) |
