从org-mode导出到HTML时更改文本颜色

6

在 .org 文件中,可以非常容易地指定文本修饰符,例如加粗、斜体、删除线等(请参见链接)。

同样,是否有办法仅为 .org 文件中的小部分文本指定文本颜色,以便在导出的 html 文件中适当着色?我认为这在快速记录重点笔记时非常有用。

期望的行为:

This is a sample sentence in normal text color.
<font color="red">
This is a sample sentence in red text color.
</font>
<font color="green">
This is a sample sentence in green text color.
</font>

2个回答

15

你可以使用一个

#+MACRO: color @@html:<font color="$1">$2</font>@@

* This is a test

This is a sample sentence in normal text color.

{{{color(red,This is a sample sentence in red text color.)}}}

{{{color(green,This is a sample sentence in green text color.)}}}

有一个限制,即第二个参数不能包含逗号(以及可能还有其他一些字符)。


1
太棒了!它也适用于 org-reveal - Picaud Vincent
3
我刚刚在这里找到了一个很棒的宏列表(颜色,高亮等):https://github.com/fniessen/org-macros/blob/master/README.org - Picaud Vincent

4
如果你对宏感到烦恼,那么在你的Emacs配置文件中添加以下内容:
(org-add-link-type
 "color"
 (lambda (path)
   (message (concat "color "
                    (progn (add-text-properties
                            0 (length path)
                            (list 'face `((t (:foreground ,path))))
                            path) path))))
 (lambda (path desc format)
   (cond
    ((eq format 'html)
     (format "<span style=\"color:%s;\">%s</span>" path desc))
    ((eq format 'latex)
     (format "{\\color{%s}%s}" path desc)))))

在 org-mode 中的示例:

    - This is [[color:green][green text]]
    - This is [[color:red][red]]

org-faq


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接