From mboxrd@z Thu Jan 1 00:00:00 1970
From: Kaushal Modi
Subject: RFC: Proposal for an Org Special Block for ox-html
Date: Thu, 24 May 2018 09:40:30 -0400
Message-ID:
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="0000000000003e3541056cf3ccf4"
Return-path:
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52477)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1fLqU2-0004s6-Q6
for emacs-orgmode@gnu.org; Thu, 24 May 2018 09:40:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1fLqU1-00069V-Ci
for emacs-orgmode@gnu.org; Thu, 24 May 2018 09:40:46 -0400
Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:51390)
by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
(Exim 4.71) (envelope-from )
id 1fLqU1-00068g-0h
for emacs-orgmode@gnu.org; Thu, 24 May 2018 09:40:45 -0400
Received: by mail-wm0-x230.google.com with SMTP id j4-v6so5279059wme.1
for ; Thu, 24 May 2018 06:40:44 -0700 (PDT)
List-Id: "General discussions about Org-mode."
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
Sender: "Emacs-orgmode"
To: emacs-org list
--0000000000003e3541056cf3ccf4
Content-Type: text/plain; charset="UTF-8"
Hello,
Yesterday, I came up with a way to generate the HTML details disclosure
fairly easily using Org Special Blocks. I implemented that in ox-hugo. But
I believe the same would be useful for ox-html too.
Here's the relevant code snippet:
((string= block-type "details")
;; Recognize Org Special blocks like:
;; #+begin_details
;; summary. This will be wrapped in and
;; ---
;; details
;; #+end_details
(let* ((is-open (member "open" (org-element-property :attr_html
special-block)))
(str1 (org-blackfriday-special-block special-block contents
nil))
;; Insert a new-line before the closing tag
;; for correct Markdown parsing for cases when the
;; Special Block content ends a code block. Without this
;; inserted newline, the Markdown converted content will
;; look like below, and Blackfriday won't parse it
;; correctly.
;; ```emacs-lisp
;; (message "a code block")
;; ```
;; A closing
tag is also added.. the opening
;; tag is later added in the `str2' var if summary is
;; present, else in `str3' var.
(str1 (replace-regexp-in-string "\\'" "\n
\\&"
str1))
;; Detect the summary divider special string "---". It
;; must begin at the beginning of a line. Also ensure to
;; replace only the first match, if any.
;; Also add the opening tag with "details" class
;; so that just as CSS rules can be set for summary
;; ("details summary"), they can be set for the details
;; portion following the too, using "details
;; .details".
(str2 (replace-regexp-in-string
"^\\(---\\)\n\\(.\\|\n\\)*\\'"
"
"
str1 nil nil 1))
(has-summary (not (string= str1 str2)))
str3)
;; (message "[DBG details/summary]: is-open:%S `%s' `%s'" is-open
str1 str2)
(setq str3 (if has-summary
(replace-regexp-in-string "\\`"
"\\&" str2)
(replace-regexp-in-string "\\`" "\\&" str2)))
(if is-open
(replace-regexp-in-string "\\`\\(" "\\1 open>" str3)
str3)))
I used "---" as the summary/details divider so that even if someone exports
that Org document to HTML without that support in ox-html, it exports as
Summary — Details.
See this for examples: https://ox-hugo.scripter.co/doc/details-and-summary/
Here is the full org-hugo-special-block:
https://github.com/kaushalmodi/ox-hugo/blob/14533c96195c90e417fcbde9d938650e83a39125/ox-hugo.el#L2239-L2363
If this feature is approved for addition to ox-html, I can make a formal
patch where instead of looking for "---", I look for the appropriate string
based on the value of (plist-get info :with-special-strings).
Thanks!
Kaushal
--
Kaushal Modi
--0000000000003e3541056cf3ccf4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: base64
PGRpdiBkaXI9Imx0ciI+PGRpdj5IZWxsbyw8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2Plllc3Rl
cmRheSwgSSBjYW1lIHVwIHdpdGggYSB3YXkgdG8gZ2VuZXJhdGUgdGhlIEhUTUwgZGV0YWlscyBk
aXNjbG9zdXJlIGZhaXJseSBlYXNpbHkgdXNpbmcgT3JnIFNwZWNpYWwgQmxvY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