From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: [patch][ox-html] Support for level based containers
Date: Sun, 16 Mar 2014 14:10:43 +0100 [thread overview]
Message-ID: <87vbveqofg.fsf@gmail.com> (raw)
In-Reply-To: <87ha6z3vbi.fsf@gmx.us> (rasmus@gmx.us's message of "Sun, 16 Mar 2014 00:18:09 +0100")
Hello,
Rasmus <rasmus@gmx.us> writes:
> This patch allows different containers in ox-html.el depending on the
> level of the heading. For example, it is possible to get a container
> structure like this (level . container):
>
> * . section
> ** . article
> *** . div
>
> This is good for HTML5 at least, and I suspect also for ox-publish
> projects. I don't know if this additional semantics is useful for
> "HTML4".
Thank you for the patch.
> Let me know if you find you'd be willing to merge something like this
I don't know enough HTML to have an opinion here.
> and what changes are necessary, if any.
Some comments follow.
> +(defcustom org-html-container-element '(("div" . "section")
> + ("div" . "article")
> + ("div" . "div"))
> + "HTML elements to use for wrapping sections.
> Can be set with the in-buffer HTML_CONTAINER property or for
> publishing, with :html-container.
>
> -Note that changing the default will prevent you from using
> -org-info.js for your website."
> +Should be a list of cons cells with positions corresponding to a
A "list of cons cells" is an "alist".
> +section. If `org-html-html5-fancy' is t the cdr is used
> +otherwise the car.
"is non-nil" is better than "is t". Also, you shouldn't use
`org-html-html5-fancy': see below.
> +Note that changing the default will prevent you from
> +using org-info.js for your website."
> :group 'org-export-html
> :version "24.4"
> :package-version '(Org . "8.0")
> - :type 'string)
> + :type '(repeat (cons string string)))
There is an `alist' type. See (info "(elisp) Composite Types")
> + (let* ((hc (plist-get info :html-container))
> + (n (org-export-get-relative-level headline info)))
You don't need a starred `let' here. Also, I suggest to not use short
variable names. IMO "container-alist" is better than "hc" and "level"
better than "n".
> + (cond ((listp hc)
> + (or (funcall (if org-html-html5-fancy 'cdr-safe 'car-safe)
> + (nth (1- (min n (length hc))) hc)) "div"))
You shouldn't use directly the variable `org-html-html5-fancy' since its
value can be overridden with external properties (e.g., during
a publishing process, with a specific setup). Instead, it should be:
(plist-get info :html-html5-fancy)
As a rule of thumb, don't use variables when there's a property in INFO
for them.
Also, I don't think you need to use `car-safe' instead of `car' and
`cdr-safe' instead of `cdr'.
Eventually, due to the (min n (length hc)) (which should be documented
in the docstring) and the fact that the alist cannot be empty, the
`funcall' never evaluates to nil. Therefore, the `or' is not necessary.
> + ((and (stringp hc) (= 1 n))
> + (plist-get info :html-container))
Note that this branch is always false since HC shouldn't be a string,
per the defcustom type, but an alist.
> + (t "div")))))
Given the recommendations above, the whole `cond' could be rewritten:
(funcall (if (plist-get info :html-html5-fancy) #'cdr #'car)
(nth (1- (min level (length container-alist))) container-alist))
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2014-03-16 13:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-15 23:18 [patch][ox-html] Support for level based containers Rasmus
2014-03-16 13:10 ` Nicolas Goaziou [this message]
2014-03-17 0:30 ` Rasmus
2014-03-17 2:15 ` Bastien
2014-03-17 17:31 ` Rick Frankel
2014-03-17 22:26 ` Rasmus
2014-03-18 0:33 ` Rick Frankel
2014-03-18 3:31 ` Rasmus
2014-03-18 15:05 ` Rick Frankel
2014-03-18 19:41 ` Rasmus
2014-03-19 14:24 ` Rick Frankel
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vbveqofg.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=rasmus@gmx.us \
/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 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.