emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Vinh Nguyen <vinhdizzo@gmail.com>
Cc: emacs-orgmode@gnu.org, Bastien <bastien.guerry@wikimedia.fr>
Subject: Re: text color + highlight
Date: Fri, 06 Aug 2010 17:51:36 -0400	[thread overview]
Message-ID: <87mxszcsuv.fsf@gmail.com> (raw)
In-Reply-To: <AANLkTikF_BOrjHFfFNEPRA0n+TM6DR8rpuTCThvTp-j4@mail.gmail.com> (Vinh Nguyen's message of "Fri, 6 Aug 2010 09:47:03 -0700")

[-- Attachment #1: Type: text/plain, Size: 676 bytes --]

Hi,

I've recently seen similar requests on this list.

The attached patch provides a first pass at this support implementing
both in-buffer coloring given the following syntax, and html export (I
don't know the correct LaTeX syntax, but it shouldn't be hard to extend
this to LaTeX as well).  This uses something like the LaTeX Beamer
\color{}{} directive, for example...

  My name is \color{red}{eric} schulte.

Would result in the word "eric" appearing in red.  Even though I
implemented the syntax above, I'm *not* recommending this syntax, it
feels decidedly more like "latex" than "org", it was simply the only
obvious option for this initial implementation.

-- Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-introduction-of-colorization-for-html-output.patch --]
[-- Type: text/x-diff, Size: 5116 bytes --]

From a488b43b66971b16f63141d29cb61f44b959abfa Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Fri, 6 Aug 2010 11:29:33 -0400
Subject: [PATCH] introduction of colorization for html output

* lisp/org-exp.el (org-export-with-color): new customization parameter
  controlling the code colorization on export

* lisp/org-html.el (org-html-do-expand): conditional application of
  string colorization in html

  (org-export-html-colorize): apply html colorization to org-mode text

* lisp/org.el (org-fontify-colorized-text): add option to control
  in-buffer colorization of the text

  (org-do-colorize-faces): function which applies color to a buffer

  (org-set-font-lock-defaults): add coloring to the org-mode
  fontification loop
---
 lisp/org-exp.el  |    5 +++++
 lisp/org-html.el |   18 ++++++++++++++++++
 lisp/org.el      |   27 +++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 6fc5109..991a555 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -445,6 +445,11 @@ This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
   :group 'org-export-translation
   :type 'boolean)
 
+(defcustom org-export-with-color t
+  "Non-nil means apply colors to exported text."
+  :group 'org-export-translation
+  :type 'boolean)
+
 (defcustom org-export-with-footnotes t
   "If nil, export [1] as a footnote marker.
 Lines starting with [1] will be formatted as footnotes.
diff --git a/lisp/org-html.el b/lisp/org-html.el
index a12141f..3d3bdcb 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -2060,6 +2060,8 @@ If there are links in the string, don't modify these."
 	(setq s (replace-match "<\\1>" t nil s))))
   (if org-export-with-emphasize
       (setq s (org-export-html-convert-emphasize s)))
+  (if org-export-with-color
+      (setq s (org-export-html-colorize s)))
   (if org-export-with-special-strings
       (setq s (org-export-html-convert-special-strings s)))
   (if org-export-with-sub-superscripts
@@ -2131,6 +2133,22 @@ If there are links in the string, don't modify these."
 	(setq s (1+ s))))
     string))
 
+(defun org-export-html-colorize (string)
+  "Apply colors."
+  (replace-regexp-in-string
+   "\\\\color{\\(.+?\\)}{\\(.+?\\)}"
+   (lambda (text)
+     (let ((ind 7) (length (length text)))
+       (while (and (< ind length)
+		   (not (string= (substring text ind (+ 2 ind)) "}{")))
+	 (setq ind (+ 1 ind)))
+       (if (get-text-property (match-beginning 0) 'org-protected string)
+	   text
+	 (concat "<span style=\"color: " (substring text 7 ind)
+		 ";\">" (substring text (+ 2 ind) (- length 1))
+		 "</span>"))))
+   string))
+
 (defun org-open-par ()
   "Insert <p>, but first close previous paragraph if any."
   (org-close-par-maybe)
diff --git a/lisp/org.el b/lisp/org.el
index d2c1fdf..fe98fb0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3282,6 +3282,12 @@ Changing this variable requires a restart of Emacs to take effect."
   :group 'org-appearance
   :type 'boolean)
 
+(defcustom org-fontify-colorized-text t
+  "Non-nil means colorize colored text.
+Changing this variable requires a restart of Emacs to take effect."
+  :group 'org-appearance
+  :type 'boolean)
+
 (defcustom org-fontify-whole-heading-line nil
   "Non-nil means fontify the whole line for headings.
 This is useful when setting a background color for the
@@ -4920,6 +4926,21 @@ The time stamps may be either active or inactive.")
       (backward-char 1))
     rtn))
 
+(defun org-do-colorize-faces (limit)
+  "Run through the buffer and add overlays to colored text."
+  (let ((org-color-re "\\\\color{\\(.+?\\)}{\\(.+?\\)}"))
+    (while (re-search-forward org-color-re limit t)
+      ;; hide wrapper
+      (add-text-properties (match-beginning 0) (+ 2 (match-end 1))
+			   '(invisible org-link))
+      (add-text-properties (- (match-end 0) 1) (match-end 0)
+			   '(invisible org-link))
+      ;; color text
+      (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
+				       'face
+				       `((t (:foreground ,(match-string 1))))))
+    rtn))
+
 (defun org-emphasize (&optional char)
   "Insert or change an emphasis, i.e. a font like bold or italic.
 If there is an active region, change that region to a new emphasis.
@@ -5367,6 +5388,7 @@ For plain list items, if they are matched by `outline-regexp', this returns
 
 (defun org-set-font-lock-defaults ()
   (let* ((em org-fontify-emphasized-text)
+	 (co org-fontify-colorized-text)
 	 (lk org-activate-links)
 	 (org-font-lock-extra-keywords
 	  (list
@@ -5429,6 +5451,11 @@ For plain list items, if they are matched by `outline-regexp', this returns
                (if (featurep 'xemacs)
                    '(org-do-emphasis-faces (0 nil append))
                  '(org-do-emphasis-faces)))
+	   ;; Color
+	   (if co
+               (if (featurep 'xemacs)
+                   '(org-do-colorize-faces (0 nil append))
+                 '(org-do-colorize-faces)))
 	   ;; Checkboxes
 	   '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
 	     2 'org-checkbox prepend)
-- 
1.7.0.4


[-- Attachment #3: Type: text/plain, Size: 1568 bytes --]


Vinh Nguyen <vinhdizzo@gmail.com> writes:

> On Fri, Aug 6, 2010 at 2:18 AM, Bastien <bastien.guerry@wikimedia.fr> wrote:
>> Hi Vinh,
>>
>> Vinh Nguyen <vinhdizzo@gmail.com> writes:
>>
>>> I was wondering if there is an easy way to markup the color of the
>>> text for html output (and highlight as well).  When I prepare meeting
>>> minutes I'd like to color some things and highlight certain things.
>>> Right now, I am using emphasizing a major portion of the text.  It
>>> would be great to have colors and highlights to draw attention to
>>> certain items.
>>
>> I don't understand your request: what portion of org-mode buffer do you
>> want to highlight?  based on what criteria?
>>
>
> Apologies for the ambiguity.  In the org, we can use *text* and the
> word "text" would be bold in the html output.  I was wondering if
> there is a markup that would change the color, eg, \{red}[text], or
> something of that sort.  I don't think it exists.  If I wanted to
> implement this myself, what should I start with.  Ditto with
> highlights (say, highlight text yellow).
>
> Something more on org-mode's line would be like setting a variable
> #+ color=red
> and with some new symbols, say ^text^, the color of "text" would be
> red in the html output.
>
> Hope this clears things up.
>> --
>>  Bastien
>>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  parent reply	other threads:[~2010-08-06 21:51 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05 20:42 text color + highlight Vinh Nguyen
2010-08-06  9:18 ` Bastien
2010-08-06 16:47   ` Vinh Nguyen
2010-08-06 20:28     ` Seweryn
2010-08-06 21:51     ` Eric Schulte [this message]
2010-08-06 23:42       ` Vinh Nguyen
2010-08-07  3:15         ` Eric Schulte
2010-08-07  3:57           ` Dan Davison
2010-08-08 14:59           ` Vinh Nguyen
2010-08-08 21:00             ` Eric Schulte
2010-08-09  6:28               ` Carsten Dominik
2010-08-09  7:37                 ` Robert Klein
2010-08-09  7:40                   ` Robert Klein
2010-08-10  6:14                 ` Christian Moe
2010-08-10  7:06                   ` Carsten Dominik
2010-08-10  9:30                     ` Christian Moe
2010-08-10 15:06                       ` Eric Schulte
2010-08-10 18:38                         ` Christian Moe
2010-08-10 21:39                           ` David Maus
2010-08-10 23:02                             ` Christian Moe
2010-08-10 23:47                               ` Eric Schulte
2010-08-11  6:48                     ` Dan Davison
2010-08-11 14:32                       ` Samuel Wales
2010-08-10 23:14                   ` Samuel Wales
2010-08-11  6:03                     ` Jan Böcker
2010-08-09  6:58               ` Eric Schulte
2010-08-09  7:05                 ` Samuel Wales
2010-08-09  5:17           ` Jambunathan K
2010-08-09  5:52             ` Noorul Islam K M
2010-08-07  4:52       ` Nick Dokos
2010-08-07 12:17       ` Sebastian Rose
2010-08-08 17:46         ` Samuel Wales
2010-09-09 16:15 ` Vinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxszcsuv.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=bastien.guerry@wikimedia.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=vinhdizzo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).