Emacs tweaks: Export Org checkboxes using UTF-8 symbols
Posted: - Modified: | emacs, org, tipsorg-html-checkbox-type
variable, which you can set to unicode
. Use M-x customize-variable org-html-checkbox-type to see if you have it.This snippet turns - [X]
into ☑ and - [ ]
into ☐.
(defun sacha/org-html-checkbox (checkbox) "Format CHECKBOX into HTML." (case checkbox (on "<span class=\"check\">☑</span>") ; checkbox (checked) (off "<span class=\"checkbox\">☐</span>") (trans "<code>[-]</code>") (t ""))) (defadvice org-html-checkbox (around sacha activate) (setq ad-return-value (sacha/org-html-checkbox (ad-get-arg 0))))
To find this code, I searched ox-html.el
for [
. Eventually I found org-html-checkbox
, which is directly called by org-html-format-list-item
instead of being a function variable that you can change. So that meant I needed to override the behaviour of org-html-checkbox
through defadvice
. You can see above how I wrap advice around org-html-checkbox
and replace the return value with my own function. For more about advice, read the Emacs Lisp Intro manual.
To find the hex codes for the UTF-8 characters, I searched Google for UTF-8 checkbox and found BALLOT BOX WITH CHECK. I used the hex code so that I didn't have to worry about encoding issues. I tested it by updating one of my weekly reviews. Tada!
Inspired by Grant from Wisdom and Wonder.
7 comments
Grant Rettke
2014-03-27T02:40:42ZThat works perfectly. Thank you for that!
Leu
2014-05-02T11:44:31ZHi, thank you for your post,it is really attractive, but why my org-mode does not possess that variable? Of course, the function does not work, too.
sachac
2014-05-02T23:02:15ZIf you're using the Org built into Emacs 24, that's still version 7, which could explain why that doesn't work. You can install Org from MELPA in order to upgrade to a newer version. You will need to start with emacs -q, then follow the instructions from MELPA's getting started guide (http://melpa.milkbox.net/#/... to load package and add MELPA to your sources list. Then you can use M-x package-install to install org. Hope that helps!
Leu
2014-05-04T03:18:25ZMany thanks. I will try as you said, and I think it will work absolutely!
Mingshen
2014-06-13T11:33:57ZI use the latest version of Org 8.2.6, but still cannot find org-html-checkbox-type variable. Could you give me some advise?
Fernando Basso
2016-08-17T13:35:29ZI wanted to use ✔ in place of those X in emacs itself. Could not find a way so far...
Hao Jiang
2018-05-21T17:43:34ZThanks for the solution!