* 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 . "☑") (off . "☐") (trans . "☐")))
+ (ascii .
+ ((on . "<code>[X]</code>")
+ (off . "<code>[ ]</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>[ ]</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
* Re: html checkbox output
2013-12-06 21:53 html checkbox output Rick Frankel
@ 2013-12-06 22:37 ` Nicolas Goaziou
2014-01-04 9:36 ` Bastien
0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2013-12-06 22:37 UTC (permalink / raw)
To: emacs-orgmode
Hello,
Rick Frankel <rick@rickster.com> writes:
> 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.
A new buffer keyword (which needs to be documented in org.texi),
a defcustom with a completely free sexp... Isn't it a bit too much for
mere checkboxes? Filters provide almost the same functionality:
(defun my-checkbox-filter (item backend info)
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "\\`.*\\(<code>\\[\\(X\\| \\|-\\)\\]</code>\\).*$"
(lambda (rep)
(let ((check (match-string 2 rep)))
(cond ((equal check "X") "☑")
((equal check "-") "☐")
(t "☐"))))
item
nil nil 1)))
(add-to-list 'org-export-filter-item-functions 'my-checkbox-filter)
Anyway, here are a few comments.
> +(defcustom org-html-checkbox-type "ascii"
> + "The type of checkboxes to use for html export. See
First line of a docstring has to be a single complete sentence.
> +(defun org-html-checkbox (checkbox info)
> + "Format CHECKBOX into HTML. This can be overriden on a
Ditto.
> + (cdr
> + (assoc checkbox
(assq checkbox
> + (if (listp checkboxes) checkboxes
> + (if (string-equal (substring checkboxes 0 1) "(")
(if (eq (aref checkboxes 0) ?\()
> + (read checkboxes)
This looks cheesy. `read'? Do you really want to parse arbitrary Sexps?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: html checkbox output
2013-12-06 22:37 ` Nicolas Goaziou
@ 2014-01-04 9:36 ` Bastien
2014-01-06 11:10 ` Nicolas Goaziou
2014-01-07 12:47 ` Rick Frankel
0 siblings, 2 replies; 7+ messages in thread
From: Bastien @ 2014-01-04 9:36 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Hi Nicolas and Rick,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> A new buffer keyword (which needs to be documented in org.texi),
> a defcustom with a completely free sexp... Isn't it a bit too much for
> mere checkboxes?
Personally I think the defcustom is enough, as this choice is likely
to be made for all Org documents.
> Filters provide almost the same functionality:
>
> (defun my-checkbox-filter (item backend info)
> (when (org-export-derived-backend-p backend 'html)
> (replace-regexp-in-string "\\`.*\\(<code>\\[\\(X\\| \\|-\\)\\]</code>\\).*$"
> (lambda (rep)
> (let ((check (match-string 2 rep)))
> (cond ((equal check "X") "☑")
> ((equal check "-") "☐")
> (t "☐"))))
> item
> nil nil 1)))
> (add-to-list 'org-export-filter-item-functions 'my-checkbox-filter)
Yes, but a defcustom would be easier.
> Anyway, here are a few comments.
>
>> +(defcustom org-html-checkbox-type "ascii"
>> + "The type of checkboxes to use for html export. See
>
> First line of a docstring has to be a single complete sentence.
>
>> +(defun org-html-checkbox (checkbox info)
>> + "Format CHECKBOX into HTML. This can be overriden on a
>
> Ditto.
>
>> + (cdr
>> + (assoc checkbox
>
> (assq checkbox
>
>> + (if (listp checkboxes) checkboxes
>> + (if (string-equal (substring checkboxes 0 1) "(")
>
> (if (eq (aref checkboxes 0) ?\()
>
>> + (read checkboxes)
>
> This looks cheesy. `read'? Do you really want to parse arbitrary
> Sexps?
Can we re-work Rick's patch/code and add this feature? Rick,
are you still on it?
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: html checkbox output
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
1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2014-01-06 11:10 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
Hello,
Bastien <bzg@gnu.org> writes:
> Hi Nicolas and Rick,
>
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> A new buffer keyword (which needs to be documented in org.texi),
>> a defcustom with a completely free sexp... Isn't it a bit too much for
>> mere checkboxes?
>
> Personally I think the defcustom is enough, as this choice is likely
> to be made for all Org documents.
>
>> Filters provide almost the same functionality:
>>
>> (defun my-checkbox-filter (item backend info)
>> (when (org-export-derived-backend-p backend 'html)
>> (replace-regexp-in-string "\\`.*\\(<code>\\[\\(X\\| \\|-\\)\\]</code>\\).*$"
>> (lambda (rep)
>> (let ((check (match-string 2 rep)))
>> (cond ((equal check "X") "☑")
>> ((equal check "-") "☐")
>> (t "☐"))))
>> item
>> nil nil 1)))
>> (add-to-list 'org-export-filter-item-functions 'my-checkbox-filter)
>
> Yes, but a defcustom would be easier.
As long as it doesn't let you write completely free sexps. Otherwise,
a function is equally complex.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: html checkbox output
2014-01-06 11:10 ` Nicolas Goaziou
@ 2014-01-06 12:54 ` Bastien
0 siblings, 0 replies; 7+ messages in thread
From: Bastien @ 2014-01-06 12:54 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> As long as it doesn't let you write completely free sexps.
I agree. But this is a very minor issue with Rick's patch,
the bulk of the work is done and I'd be glad to see it applied,
with the limitations we've been discussing. If Rick is on it,
let's wait for this.
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: html checkbox output
2014-01-04 9:36 ` Bastien
2014-01-06 11:10 ` Nicolas Goaziou
@ 2014-01-07 12:47 ` Rick Frankel
2014-01-07 12:59 ` Bastien
1 sibling, 1 reply; 7+ messages in thread
From: Rick Frankel @ 2014-01-07 12:47 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode, Nicolas Goaziou
Bastien-
Top quoting to keep the history but save the search to the bottom
:)...
Yes, i will rework/simplify the patch (remove the free-form option and
the in-buffer setting), but I've been short on time the last week or
so.. Will fix it and push this week.
BTW, I've kept ascii output as the default mostly so I don't break the
regression test. Should I leave it alone or make utf-8 the default and
update the test?
rick
On Sat, Jan 04, 2014 at 10:36:13AM +0100, Bastien wrote:
> Hi Nicolas and Rick,
>
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
> > A new buffer keyword (which needs to be documented in org.texi),
> > a defcustom with a completely free sexp... Isn't it a bit too much for
> > mere checkboxes?
>
> Personally I think the defcustom is enough, as this choice is likely
> to be made for all Org documents.
>
> > Filters provide almost the same functionality:
> >
> > (defun my-checkbox-filter (item backend info)
> > (when (org-export-derived-backend-p backend 'html)
> > (replace-regexp-in-string "\\`.*\\(<code>\\[\\(X\\| \\|-\\)\\]</code>\\).*$"
> > (lambda (rep)
> > (let ((check (match-string 2 rep)))
> > (cond ((equal check "X") "☑")
> > ((equal check "-") "☐")
> > (t "☐"))))
> > item
> > nil nil 1)))
> > (add-to-list 'org-export-filter-item-functions 'my-checkbox-filter)
>
> Yes, but a defcustom would be easier.
>
> > Anyway, here are a few comments.
> >
> >> +(defcustom org-html-checkbox-type "ascii"
> >> + "The type of checkboxes to use for html export. See
> >
> > First line of a docstring has to be a single complete sentence.
> >
> >> +(defun org-html-checkbox (checkbox info)
> >> + "Format CHECKBOX into HTML. This can be overriden on a
> >
> > Ditto.
> >
> >> + (cdr
> >> + (assoc checkbox
> >
> > (assq checkbox
> >
> >> + (if (listp checkboxes) checkboxes
> >> + (if (string-equal (substring checkboxes 0 1) "(")
> >
> > (if (eq (aref checkboxes 0) ?\()
> >
> >> + (read checkboxes)
> >
> > This looks cheesy. `read'? Do you really want to parse arbitrary
> > Sexps?
>
> Can we re-work Rick's patch/code and add this feature? Rick,
> are you still on it?
>
> Thanks,
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: html checkbox output
2014-01-07 12:47 ` Rick Frankel
@ 2014-01-07 12:59 ` Bastien
0 siblings, 0 replies; 7+ messages in thread
From: Bastien @ 2014-01-07 12:59 UTC (permalink / raw)
To: Rick Frankel; +Cc: Nicolas Goaziou, emacs-orgmode
Rick Frankel <rick@rickster.com> writes:
> Yes, i will rework/simplify the patch (remove the free-form option and
> the in-buffer setting), but I've been short on time the last week or
> so.. Will fix it and push this week.
Thanks!
> BTW, I've kept ascii output as the default mostly so I don't break the
> regression test. Should I leave it alone or make utf-8 the default and
> update the test?
I'm for keeping the ascii output as the default one,
but if people prefer the utf-8 one, so be it.
--
Bastien
^ permalink raw reply [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 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).