Changing color of text in html export from org-mode

Viewed 3766

It is possible to specify text modifiers such as bold, italics, strikethrough, etc. in a .org file very easily (see link).

Similarly, is there any way to specify text color for just a small section of a .org file such that the text is appropriately colored in the exported html file? I think this would be quite useful while taking highlighted notes fast.

Expected behavior:

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 Answers

If you are annoyed by macros. Then add the following to your Emacs config,

(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)))))

example in org-mode:

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

org-faq

Related