Skip to content

Commit

Permalink
Support Inline HTML5 element special blocks
Browse files Browse the repository at this point in the history
Example: Use #+BEGIN_mark and #+END_mark to mark/highlight text in HTML5.
  • Loading branch information
kaushalmodi committed Jan 15, 2018
1 parent 8cc6b9a commit a069378
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
24 changes: 19 additions & 5 deletions ox-blackfriday.el
Expand Up @@ -30,6 +30,13 @@
(defconst org-blackfriday-table-right-border " ")
(defconst org-blackfriday-table-separator "| ")

(defconst org-blackfriday-html5-inline-elements
'("audio" "details" "command" "datalist" "mark" "meter"
"nav" "source" "summary" "time")
"New inline elements in html5.
http://itman.in/en/inline-elements-html5/.")

(defvar org-blackfriday--hrule-inserted nil
"State variable to track if the horizontal rule was inserted.
This check is specifically track if that horizontal rule was
Expand Down Expand Up @@ -570,7 +577,9 @@ CONTENTS holds the contents of the block.
This function is adapted from `org-html-special-block'."
(let* ((block-type (org-element-property :type special-block))
(html5-fancy (member block-type org-html-html5-elements))
(html5-inline-fancy (member block-type org-blackfriday-html5-inline-elements))
(html5-block-fancy (member block-type org-html-html5-elements))
(html5-fancy (or html5-inline-fancy html5-block-fancy))
(attributes (org-export-read-attribute :attr_html special-block)))
(unless html5-fancy
(let ((class (plist-get attributes :class)))
Expand All @@ -589,11 +598,16 @@ This function is adapted from `org-html-special-block'."
(attr-str (if (org-string-nw-p attr-str)
(concat " " attr-str)
"")))
(if html5-fancy
(format "<%s%s>\n<%s></%s>\n\n%s\n</%s>" ;See footnote 1
block-type attr-str block-type block-type contents block-type)
(cond
(html5-inline-fancy
(format "<%s%s>%s</%s>"
block-type attr-str contents block-type))
(html5-block-fancy
(format "<%s%s>\n<%s></%s>\n\n%s\n</%s>" ;See footnote 1
block-type attr-str block-type block-type contents block-type))
(t
(format "<div%s>\n<div></div>\n\n%s\n</div>" ;See footnote 1
attr-str contents)))))
attr-str contents))))))

;;;; Src Block
(defun org-blackfriday-src-block (src-block _contents info)
Expand Down
6 changes: 6 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -2685,6 +2685,12 @@ This is /an article/.
| g | h | i |
| j | k | l |
#+END_section
*** An inline HTML5 element
Unmarked.
#+BEGIN_mark
/Some/ *marked* text --- 2.5.
#+END_mark
Unmarked again.
** DIV-wrapped Blocks
*** DIV without NAME, class or id
#+BEGIN_something
Expand Down
10 changes: 10 additions & 0 deletions test/site/content/posts/special-blocks.md
Expand Up @@ -45,6 +45,16 @@ _Some_ **text** --- 2
</section>


### An inline HTML5 element {#an-inline-html5-element}

Unmarked.

<mark>_Some_ **marked** text --- 2.5.
</mark>

Unmarked again.


## DIV-wrapped Blocks {#div-wrapped-blocks}


Expand Down

0 comments on commit a069378

Please sign in to comment.