先上效果图:
目前只能使用 latex 或 html 导出, 背景不支持 latex 导出
在 org 文件开头加上两个 macros:
#+macro: color @@html:<span style="color:$1">$2</span>@@@@latex:\textcolor{$1}{$2}@@
#+macro: bgcolor @@html:<span style="background-color:$1;">$2</span>@@@@latex:[email protected]@
以下的代码为新的 syntax 增加高亮
(font-lock-add-keywords
'org-mode
'(("{{{[ \n]*\\(bg\\)?color[ \n]*(\\([#0-9a-zA-Z]+\\)[ \n]*,\\([^,]+?\\))}}}"
(2 font-lock-comment-face t t)
(3 (let ((bg (match-string 1))
(color (match-string 2)))
(list (if (equal bg "bg") :background :foreground) color))
prepend t)))
;; 这里必须是 non-nil 否则被 org-macros 的 font-lock 覆盖
'append)
这个链接里有更多的 org-macros