diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2021-06-01 02:45:59 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2021-06-01 02:45:59 (GMT) |
| commit | f3aa7c99f092157ccd3182ffeea922240400a568 (patch) | |
| tree | b67401cf8986dbfc4f841b416beeeb7fbb8f7901 /lisp | |
| parent | 2ecd1f52b071bc7fd25c0e88c2089feac0efd23a (diff) | |
| download | dotemacs-f3aa7c99f092157ccd3182ffeea922240400a568.zip dotemacs-f3aa7c99f092157ccd3182ffeea922240400a568.tar.gz dotemacs-f3aa7c99f092157ccd3182ffeea922240400a568.tar.bz2 | |
HTML export with dark background needs css support
Diffstat (limited to 'lisp')
| -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) |
