Browse Source

HTML export: Also wrap tags into classes.

Like TODO keywords before, now also tags each get their own CSS class,
given by the tag itself.  Invalid characters in tags are all replaced
by "_" to make sure the resulting HTML remains valid.

Two new variables can be used to add a prefix to the class names for
TODO keywords and tags.
Carsten Dominik 16 years ago
parent
commit
4be7e8e9b3
4 changed files with 86 additions and 13 deletions
  1. 10 3
      ORGWEBPAGE/Changes.org
  2. 24 6
      doc/org.texi
  3. 10 0
      lisp/ChangeLog
  4. 42 4
      lisp/org-exp.el

+ 10 - 3
ORGWEBPAGE/Changes.org

@@ -77,11 +77,11 @@ http://orgmode.org/worg/org-tutorials/org-R/org-R.php
 
 
 Thanks to Dan for this great contribution.
 Thanks to Dan for this great contribution.
 
 
-*** Allow individual formatting of each TODO keyword in HTML export
+*** Allow individual formatting of TODO keyword and tags in HTML export
 
 
 TODO keywords in HTML export have the CSS class =todo= or =done=.
 TODO keywords in HTML export have the CSS class =todo= or =done=.
-In addition to this, each keyword has now itself as class, so you
-could do this in your CSS file:
+Tags have the CSS class =tag=.  In addition to this, each keyword
+has now itself as class, so you could do this in your CSS file:
 
 
 #+begin_src css
 #+begin_src css
 .todo { font-weight:bold; }
 .todo { font-weight:bold; }
@@ -91,6 +91,13 @@ could do this in your CSS file:
 .DONE { color:green; }
 .DONE { color:green; }
 #+end_src
 #+end_src
 
 
+If any of your keywords causes conflicts with CSS classes used
+for different purposes (for example a tag "title" would cause a
+conflict with the class used for formatting the document title),
+then you can use the variables =org-export-html-tag-class-prefix=
+and =org-export-html-todo-kwd-class-prefix= to define prefixes
+for the class names for keywords, for example "kwd-".
+
 Thanks to Wanrong Lin for this request, and to Sebastian Rose for
 Thanks to Wanrong Lin for this request, and to Sebastian Rose for
 help with the implementation.
 help with the implementation.
 
 

+ 24 - 6
doc/org.texi

@@ -8334,22 +8334,40 @@ respectively.  For example
 @cindex CSS, for HTML export
 @cindex CSS, for HTML export
 @cindex HTML export, CSS
 @cindex HTML export, CSS
 
 
+@vindex org-export-html-todo-kwd-class-prefix
+@vindex org-export-html-tag-class-prefix
 You can also give style information for the exported file.  The HTML exporter
 You can also give style information for the exported file.  The HTML exporter
-assigns the following special CSS classes to appropriate parts of the
-document - your style specifications may change these, in addition to any of
-the standard classes like for headlines, tables etc.
-@example
+assigns the following special CSS classes@footnote{If the classes on TODO
+keywords and tags lead to conflicts, use the variables
+@code{org-export-html-todo-kwd-class-prefix} and
+@code{org-export-html-tag-class-prefix} to make them unique.} to appropriate
+parts of the document - your style specifications may change these, in
+addition to any of the standard classes like for headlines, tables etc.
+@example
+.title             @r{document title}
+.author            @r{author information}
+.date              @r{publishing date}
 .todo              @r{TODO keywords, all not-done states}
 .todo              @r{TODO keywords, all not-done states}
 .done              @r{the DONE keywords, all stated the count as done}
 .done              @r{the DONE keywords, all stated the count as done}
-WAITING            @r{Each TODO keyword also uses a class named after itself}
+.WAITING           @r{each TODO keyword also uses a class named after itself}
 .timestamp         @r{time stamp}
 .timestamp         @r{time stamp}
 .timestamp-kwd     @r{keyword associated with a time stamp, like SCHEDULED}
 .timestamp-kwd     @r{keyword associated with a time stamp, like SCHEDULED}
 .tag               @r{tag in a headline}
 .tag               @r{tag in a headline}
+._HOME             @r{each tag uses itself as a class, "@@" replaced by "_"}
 .target            @r{target for links}
 .target            @r{target for links}
-div.figure         @r{how to format an inlined image}
 .linenr            @r{the line number in a code example}
 .linenr            @r{the line number in a code example}
 .code-highlighted  @r{for highlighting referenced code lines}
 .code-highlighted  @r{for highlighting referenced code lines}
 .section-number-N  @r{section number in headlines, different for each level}
 .section-number-N  @r{section number in headlines, different for each level}
+.footnotes         @r{footnote section headline}
+.footref           @r{a footnote reference (also a <sup>)}
+.footnote          @r{footnote definition paragraph}
+.footnum           @r{footnote number in footnote definition (also <sup>)}
+div.figure         @r{how to format an inlined image}
+div.outline-N      @r{div for outline level N (headline plus text))}
+div.outline-text-N @r{extra div for text at outline level N}
+.src               @r{source code}
+.example           @r{normal example}
+.verse             @r{verse paragraph}
 @end example
 @end example
 
 
 @vindex org-export-html-style-default
 @vindex org-export-html-style-default

+ 10 - 0
lisp/ChangeLog

@@ -1,5 +1,15 @@
 2009-02-20  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-02-20  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-exp.el (org-export-htm-get-tag-class-name)
+	(org-export-htm-get-todo-kwd-class-name): New functions.
+	(org-export-html-tag-class-prefix)
+	(org-export-html-todo-kwd-class-prefix): New options.
+	(org-export-as-html): Call
+	`org-export-html-get-todo-kwd-class-name'.
+	(org-html-level-start): Wrap tags into classes.
+	(org-export-html-get-tag-class-name)
+	(org-export-html-get-todo-kwd-class-name): New functions.
+
 	* org-export-latex.el (org-export-latex-collect-header-macros):
 	* org-export-latex.el (org-export-latex-collect-header-macros):
 	Remove fields that are used anyway.
 	Remove fields that are used anyway.
 	(org-export-latex-make-header): Insert the options earlier.
 	(org-export-latex-make-header): Insert the options earlier.

+ 42 - 4
lisp/org-exp.el

@@ -646,6 +646,23 @@ settings with <style>...</style> tags."
 ;;;###autoload
 ;;;###autoload
 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
 
 
+(defcustom org-export-html-tag-class-prefix ""
+  "Prefix to clas names for TODO keywords.
+Each tag gets a class given by the tag itself, with this prefix.
+The default prefix is empty because it is nice to just use the keyword
+as a class name.  But if you get into conflicts with other, existing
+CSS classes, then this prefic can be very useful."
+  :group 'org-export-html
+  :type 'string)
+
+(defcustom org-export-html-todo-kwd-class-prefix ""
+  "Prefix to clas names for TODO keywords.
+Each TODO keyword gets a class given by the keyword itself, with this prefix.
+The default prefix is empty because it is nice to just use the keyword
+as a class name.  But if you get into conflicts with other, existing
+CSS classes, then this prefic can be very useful."
+  :group 'org-export-html
+  :type 'string)
 
 
 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
   "Format for typesetting the document title in HTML export."
   "Format for typesetting the document title in HTML export."
@@ -3744,7 +3761,8 @@ lang=\"%s\" xml:lang=\"%s\">
 					org-done-keywords)
 					org-done-keywords)
 				"done" "todo")
 				"done" "todo")
 			    " " (match-string 2 line)
 			    " " (match-string 2 line)
-			    "\"> " (match-string 2 line)
+			    "\"> " (org-export-html-get-todo-kwd-class-name
+				    (match-string 2 line))
 			    "</span>" (substring line (match-end 2)))))
 			    "</span>" (substring line (match-end 2)))))
 
 
 	  ;; Does this contain a reference to a footnote?
 	  ;; Does this contain a reference to a footnote?
@@ -4631,9 +4649,13 @@ When TITLE is nil, just close all open levels."
 			   (save-match-data
 			   (save-match-data
 			     (concat
 			     (concat
 			      "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
 			      "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
-			      (mapconcat 'identity (org-split-string
-						    (match-string 1 title) ":")
-					 "&nbsp;")
+			      (mapconcat
+			       (lambda (x)
+				 (format "<span class=\"%s\">%s</span>"
+					 (org-export-html-get-tag-class-name x)
+					 x))
+			       (org-split-string (match-string 1 title) ":")
+			       "&nbsp;")
 			      "</span>"))
 			      "</span>"))
 			 "")
 			 "")
 		       t t title)))
 		       t t title)))
@@ -4670,6 +4692,22 @@ When TITLE is nil, just close all open levels."
       (and (setq pos (next-single-property-change pos prop object))
       (and (setq pos (next-single-property-change pos prop object))
 	   (get-text-property pos prop object))))
 	   (get-text-property pos prop object))))
 
 
+(defun org-export-html-get-tag-class-name (tag)
+  "Turn tag into a valid class name.
+Replaces invalid characters with \"_\" and then prepends a prefix."
+  (save-match-data
+    (while (string-match "[^a-zA-Z0-9_]" tag)
+      (setq tag (replace-match "_" t t tag))))
+  (concat org-export-html-tag-class-prefix tag))
+
+(defun org-export-html-get-todo-kwd-class-name (kwd)
+  "Turn todo keyword into a valid class name.
+Replaces invalid characters with \"_\" and then prepends a prefix."
+  (save-match-data
+    (while (string-match "[^a-zA-Z0-9_]" kwd)
+      (setq tag (replace-match "_" t t kwd))))
+  (concat org-export-html-todo-kwd-class-prefix kwd))
+
 (defun org-html-level-close (level max-outline-level)
 (defun org-html-level-close (level max-outline-level)
   "Terminate one level in HTML export."
   "Terminate one level in HTML export."
   (if (<= level max-outline-level)
   (if (<= level max-outline-level)