Spectre
Spectre

Reputation: 684

Changing color of text in html export from org-mode

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>

Upvotes: 6

Views: 5137

Answers (2)

I.Omar
I.Omar

Reputation: 542

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

Upvotes: 4

NickD
NickD

Reputation: 6412

You can use a macro:

#+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.)}}}

with the limitation that the second argument cannot contain a comma (and maybe some other characters).

Upvotes: 15

Related Questions