emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Only use HTML5 fancy elements in HTML5
@ 2015-08-17 15:50 Eric Abrahamsen
  2015-08-17 16:51 ` Rasmus
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2015-08-17 15:50 UTC (permalink / raw)
  To: emacs-orgmode

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

Currently, if the global variable `org-html-html5-fancy' is t, some
elements of HTML export will use fancy elements even when not exporting
to HTML5 at all.

Specifically, the TITLE of a document will be wrapped in <header> tags,
even when exporting to XHTML4. I ran into this while making some epub
files and the syntax checker barked at me.

This patch fills out the check. There's growing redundancy in this file
now -- if it seems desirable to have a `org-html-html5-fancy-p' function
that encapsulates the paired checks, I'd be happy to provide that.

E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Only-use-HTML5-fancy-elements-in-HTML5.patch --]
[-- Type: text/x-diff, Size: 1224 bytes --]

From 921081b428445d42f2ee82b9be9135a95db9e084 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Mon, 17 Aug 2015 23:41:19 +0800
Subject: [PATCH] Only use HTML5 fancy elements in HTML5

* lisp/ox-html.el (org-html-template): The check for HTML5 fancy
  elements should only apply when exporting to HTML5.
---
 lisp/ox-html.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index bdcdeee..4f94090 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1932,13 +1932,15 @@ holding export options."
 	   (subtitle (plist-get info :subtitle)))
        (when title
 	 (format
-	  (if (plist-get info :html-html5-fancy)
+	  (if (and (org-html-html5-p info)
+		   (plist-get info :html-html5-fancy))
 	      "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
 	    "<h1 class=\"title\">%s%s</h1>\n")
 	  (org-export-data title info)
 	  (if subtitle
 	      (format
-	       (if (plist-get info :html-html5-fancy)
+	       (if (and (org-html-html5-p info)
+			(plist-get info :html-html5-fancy))
 		   "<p class=\"subtitle\">%s</p>\n"
 		 "\n<br>\n<span class=\"subtitle\">%s</span>\n")
 	       (org-export-data subtitle info))
-- 
2.5.0


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

* Re: [PATCH] Only use HTML5 fancy elements in HTML5
  2015-08-17 15:50 [PATCH] Only use HTML5 fancy elements in HTML5 Eric Abrahamsen
@ 2015-08-17 16:51 ` Rasmus
  2015-08-18  0:49   ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2015-08-17 16:51 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Currently, if the global variable `org-html-html5-fancy' is t, some
> elements of HTML export will use fancy elements even when not exporting
> to HTML5 at all.
>
> Specifically, the TITLE of a document will be wrapped in <header> tags,
> even when exporting to XHTML4. I ran into this while making some epub
> files and the syntax checker barked at me.
>
> This patch fills out the check. There's growing redundancy in this file
> now -- if it seems desirable to have a `org-html-html5-fancy-p' function
> that encapsulates the paired checks, I'd be happy to provide that.

Remind me, do we have a "non-fancy" HTML5 mode?

I think it's better to introduce a new function to check if fancy HTML5.
This would make it easier to adhere to the docstring of
org-html-html5-fancy:

     "This variable is ignored for anything other than HTML5 export"

Thanks,
Rasmus


-- 
This is the kind of tedious nonsense up with which I will not put

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

* Re: [PATCH] Only use HTML5 fancy elements in HTML5
  2015-08-17 16:51 ` Rasmus
@ 2015-08-18  0:49   ` Eric Abrahamsen
  2015-08-18 16:00     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2015-08-18  0:49 UTC (permalink / raw)
  To: emacs-orgmode

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

Rasmus <rasmus@gmx.us> writes:

> Hi,
>
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Currently, if the global variable `org-html-html5-fancy' is t, some
>> elements of HTML export will use fancy elements even when not exporting
>> to HTML5 at all.
>>
>> Specifically, the TITLE of a document will be wrapped in <header> tags,
>> even when exporting to XHTML4. I ran into this while making some epub
>> files and the syntax checker barked at me.
>>
>> This patch fills out the check. There's growing redundancy in this file
>> now -- if it seems desirable to have a `org-html-html5-fancy-p' function
>> that encapsulates the paired checks, I'd be happy to provide that.
>
> Remind me, do we have a "non-fancy" HTML5 mode?
>
> I think it's better to introduce a new function to check if fancy HTML5.
> This would make it easier to adhere to the docstring of
> org-html-html5-fancy:
>
>      "This variable is ignored for anything other than HTML5 export"

Yup, this was the problem. We do have "non-fancy" HTML5: just HTML5
without the use of any of the new elements like <header> or <nav>, which
aren't currently handled right by all browsers. All the various options
make for some fiddly conditionals, but I think it's worth it.

Here's another patch with a new function.

Thanks!
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-function-to-better-guard-html5-exports.patch --]
[-- Type: text/x-diff, Size: 3284 bytes --]

From d0150b8c34efb1086dd5b240b256b0cf1f053148 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Tue, 18 Aug 2015 08:42:35 +0800
Subject: [PATCH] Add function to better guard html5 exports

* lisp/ox-html.el (org-html-html5-fancy-p): New function. Check that
  we're exporting to HTML5, *and* that the user has requested fancy
  elements.
  (org-html--wrap-image, org-html-template, org-html-toc)
  (org-html-special-block): Use new function.
---
 lisp/ox-html.el | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index bdcdeee..78c8e11 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1473,6 +1473,10 @@ CSS classes, then this prefix can be very useful."
   (let ((dt (downcase (plist-get info :html-doctype))))
 	(member dt '("html5" "xhtml5" "<!doctype html>"))))
 
+(defun org-html-html5-fancy-p (info)
+  (and (plist-get info :html-html5-fancy)
+       (org-html-html5-p info)))
+
 (defun org-html-close-tag (tag attr info)
   (concat "<" tag " " attr
 	  (if (org-html-xhtml-p info) " />" ">")))
@@ -1503,8 +1507,7 @@ attributes with a nil value will be omitted from the result."
 INFO is a plist used as a communication channel.  When optional
 arguments CAPTION and LABEL are given, use them for caption and
 \"id\" attribute."
-  (let ((html5-fancy (and (org-html-html5-p info)
-			  (plist-get info :html-html5-fancy))))
+  (let ((html5-fancy (org-html-html5-fancy-p info)))
     (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
 	      "\n<div%s class=\"figure\">%s%s\n</div>")
 	    ;; ID.
@@ -1929,16 +1932,17 @@ holding export options."
    ;; Document title.
    (when (plist-get info :with-title)
      (let ((title (plist-get info :title))
-	   (subtitle (plist-get info :subtitle)))
+	   (subtitle (plist-get info :subtitle))
+	   (html5-fancy (org-html-html5-fancy-p info)))
        (when title
 	 (format
-	  (if (plist-get info :html-html5-fancy)
+	  (if html5-fancy
 	      "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
 	    "<h1 class=\"title\">%s%s</h1>\n")
 	  (org-export-data title info)
 	  (if subtitle
 	      (format
-	       (if (plist-get info :html-html5-fancy)
+	       (if html5-fancy
 		   "<p class=\"subtitle\">%s</p>\n"
 		 "\n<br>\n<span class=\"subtitle\">%s</span>\n")
 	       (org-export-data subtitle info))
@@ -2133,8 +2137,7 @@ of contents as a string, or nil if it is empty."
 			 (org-html--toc-text toc-entries)
 			 "</div>\n")))
 	(if scope toc
-	  (let ((outer-tag (if (and (org-html-html5-p info)
-				    (plist-get info :html-html5-fancy))
+	  (let ((outer-tag (if (org-html-html5-fancy-p info)
 			       "nav"
 			     "div")))
 	    (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
@@ -3181,8 +3184,7 @@ CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
   (let* ((block-type (org-element-property :type special-block))
 	 (contents (or contents ""))
-	 (html5-fancy (and (org-html-html5-p info)
-			   (plist-get info :html-html5-fancy)
+	 (html5-fancy (and (org-html-html5-fancy-p info)
 			   (member block-type org-html-html5-elements)))
 	 (attributes (org-export-read-attribute :attr_html special-block)))
     (unless html5-fancy
-- 
2.5.0


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

* Re: [PATCH] Only use HTML5 fancy elements in HTML5
  2015-08-18  0:49   ` Eric Abrahamsen
@ 2015-08-18 16:00     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2015-08-18 16:00 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Here's another patch with a new function.

Applied, thanks.

-- 
 Bastien

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

end of thread, other threads:[~2015-08-18 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-17 15:50 [PATCH] Only use HTML5 fancy elements in HTML5 Eric Abrahamsen
2015-08-17 16:51 ` Rasmus
2015-08-18  0:49   ` Eric Abrahamsen
2015-08-18 16:00     ` 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).