Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing color of text in html export from org-mode

Tags:

emacs

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>
like image 855
Spectre Avatar asked Aug 09 '17 01:08

Spectre


2 Answers

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

like image 110
NickD Avatar answered Nov 05 '22 10:11

NickD


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

like image 28
I.Omar Avatar answered Nov 05 '22 10:11

I.Omar