emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rick Frankel <rick@rickster.com>
To: emacs-orgmode@gnu.org
Subject: html checkbox output
Date: Fri, 6 Dec 2013 16:53:21 -0500	[thread overview]
Message-ID: <20131206215321.GA48654@eyeBook> (raw)

[-- 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


             reply	other threads:[~2013-12-06 21:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06 21:53 Rick Frankel [this message]
2013-12-06 22:37 ` html checkbox output 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

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=20131206215321.GA48654@eyeBook \
    --to=rick@rickster.com \
    --cc=emacs-orgmode@gnu.org \
    /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).