marsmining / ox-twbs

Export org-mode docs as HTML compatible with Twitter Bootstrap.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom special blocks support & html5

mlt opened this issue · comments

Right now all special blocks are turned into potentially non-existing tags. It would be nice to port corresponding blocks from ox-html. I'm not certain if the following will do it before cloning and submitting PR.

--- ox-twbs.el.orig     2015-10-25 20:54:33.000000000 -0500
+++ ox-twbs.el  2015-12-14 17:31:47.607772900 -0600
@@ -120,6 +120,8 @@
   '((:html-extension nil nil org-twbs-extension)
     (:html-link-org-as-html nil nil org-twbs-link-org-files-as-html)
     (:html-container "HTML_CONTAINER" nil org-twbs-container-element)
+    (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
+    (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
     (:html-link-use-abs-url nil "html-link-use-abs-url" org-twbs-link-use-abs-url)
     (:html-link-home "HTML_LINK_HOME" nil org-twbs-link-home)
     (:html-link-up "HTML_LINK_UP" nil org-twbs-link-up)
@@ -2727,11 +2729,21 @@
   (let* ((block-type (downcase
                       (org-element-property :type special-block)))
          (contents (or contents ""))
+        (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
+      (let ((class (plist-get attributes :class)))
+       (setq attributes (plist-put attributes :class
+                                   (if class (concat class " " block-type)
+                                     block-type)))))
     (setq attributes (org-twbs--make-attribute-string attributes))
     (when (not (equal attributes ""))
       (setq attributes (concat " " attributes)))
-    (format "<%s%s>\n%s</%s>" block-type attributes contents block-type)))
+    (if html5-fancy
+       (format "<%s%s>\n%s</%s>" block-type attributes
+               contents block-type)
+      (format "<div%s>\n%s\n</div>" attributes contents))))

 ;;;; Src Block

Thanks for working on this issue! I pushed a commit nearly the same as your diff. Only difference was in this project one of the first things I did was remove all the code handling different doc types. Therefore the predicate org-html--html5-fancy-p is not needed as html5 is only mode of export.

I believe this commit should bring "special block" handling support to conform according to the following docs:

Let me know your experience!

I tested the following org source:

#+BEGIN_BING
foo
#+END_BING

#+ATTR_HTML: :controls controls :width 350
#+BEGIN_VIDEO :attr_html ring
#+HTML: <source src="movie.mp4" type="video/mp4">
#+HTML: <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
#+END_VIDEO

Exports to HTML:

<div class="bing">
<p>
foo
</p>
</div>
<video controls="controls" width="350">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<p>
Your browser does not support the video tag.bar
</p>
</video>