all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* html checkbox output
@ 2013-12-06 21:53 Rick Frankel
  2013-12-06 22:37 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Rick Frankel @ 2013-12-06 21:53 UTC (permalink / raw)
  To: emacs-orgmode

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

So, here's a patch I would like a couple of people to try before i
commit it. It provides customization of checkbox formatting for html
output (unicode, ascii, checkbox input fields or custom). I couldn't
figure out how to add an association list customization with preset
options to a customization choice, so the custom option is a
partilally pre-filled sexp.

The default is still ascii, partially so that the checkbox tests don't
fail w/o being changed.

Let me know if this works for every of if it is too complex a solution
befor I apply it to master.

tia
rick

[-- Attachment #2: 0001-Add-customization-options-for-html-checkboxes.patch --]
[-- Type: text/plain, Size: 4229 bytes --]

From 41da34c352f9c3899ece8294c3f618b665f12281 Mon Sep 17 00:00:00 2001
From: Rick Frankel <rick@rickster.com>
Date: Tue, 3 Dec 2013 14:37:30 -0500
Subject: [PATCH] Add customization options for html checkboxes.

* lisp/ox-html.el (html): Add in-buffer option HTML_CHECKBOX_TYP
(org-html-checkbox-types): New constant. Contains unicode, ascii and html
checkbox alists.
(org_html_checkbox_type): New customzation variable can be set to one
of the above choices or a user-entered alist.
(org_html_checkbox): Use of `:html-checkbox-type' export option.
---
 lisp/ox-html.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 55 insertions(+), 7 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 9fa0a8c..8d0e3e3 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -126,6 +126,7 @@
     (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
     (:html-table-attributes nil nil org-html-table-default-attributes)
     (:html-table-row-tags nil nil org-html-table-row-tags)
+    (:html-checkbox-type "HTML_CHECKBOX_TYPE" nil org-html-checkbox-type)
     (:html-xml-declaration nil nil org-html-xml-declaration)
     (:html-inline-images nil nil org-html-inline-images)
     (:infojs-opt "INFOJS_OPT" nil nil)
@@ -973,6 +974,42 @@ org-info.js for your website."
 	       (list :tag "Postamble" (const :format "" postamble)
 		     (string :tag "     id") (string :tag "element"))))
 
+(defconst org-html-checkbox-types
+  '((unicode .
+     ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
+    (ascii .
+     ((on . "<code>[X]</code>")
+      (off . "<code>[&#xa0;]</code>")
+      (trans . "<code>[-]</code>")))
+    (html .
+	  ((on . "<input type='checkbox' checked='checked' />")
+	  (off . "<input type='checkbox' />")
+	  (trans . "<input type='checkbox' />"))))
+  "Alist of checkbox types.
+The cdr of each entry is an alist list three checkbox types for
+html export: \"on\", \"off\" and \"trans\".
+
+The choices are:
+  - unicode characters (html entities)
+  - ascii characters
+  - html checkboxes
+  - a user defined alist
+Note that only the ascii characters implement tri-state
+checkboxes. The other two use the \"off\" checkbox for \"trans\".")
+
+(defcustom org-html-checkbox-type "ascii"
+  "The type of checkboxes to use for html export. See
+`org-html-checkbox-types' for for the preset values."
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type '(choice
+	  (const :tag "Unicode characters" "unicode")
+	  (const :tag "Ascii characters" "ascii")
+	  (const :tag "HTML checkboxes" "html")
+	  (sexp :tag "Custom alist"
+		((on . "") (off . "") (trans . "")))))
+
 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
   "Format used for timestamps in preamble, postamble and metadata.
 See `format-time-string' for more information on its components."
@@ -2415,18 +2452,29 @@ contextual information."
 
 ;;;; Item
 
-(defun org-html-checkbox (checkbox)
-  "Format CHECKBOX into HTML."
-  (case checkbox (on "<code>[X]</code>")
-	(off "<code>[&#xa0;]</code>")
-	(trans "<code>[-]</code>")
-	(t "")))
+(defun org-html-checkbox (checkbox info)
+  "Format CHECKBOX into HTML. This can be overriden on a
+per-buffer basis with the \"HTML_CHECKBOX_TYPE\" property,
+which can be either the name of one of the entries in the
+`org-html-checkbox-types' variable or an alist of the form:
+   ((on . \"\") (off . \"\") (trans . \"\").
+See `org-html-checkbox-type' for customization."
+  (let ((checkboxes (plist-get info :html-checkbox-type)))
+    (cdr
+     (assoc checkbox
+	    (if (listp checkboxes) checkboxes
+	      (if (string-equal (substring checkboxes 0 1) "(")
+		  (read checkboxes)
+		(cdr (assoc
+		    (intern checkboxes)
+		    org-html-checkbox-types))))))))
 
 (defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     headline)
   "Format a list item into HTML."
-  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
+  (let ((checkbox (concat (org-html-checkbox checkbox info)
+			  (and checkbox " ")))
 	(br (org-html-close-tag "br" nil info)))
     (concat
      (case type
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-07 12:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-06 21:53 html checkbox output Rick Frankel
2013-12-06 22:37 ` Nicolas Goaziou
2014-01-04  9:36   ` Bastien
2014-01-06 11:10     ` Nicolas Goaziou
2014-01-06 12:54       ` Bastien
2014-01-07 12:47     ` Rick Frankel
2014-01-07 12:59       ` Bastien

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.