emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* RFC: Proposal for an Org Special Block for ox-html
@ 2018-05-24 13:40 Kaushal Modi
  2018-05-24 17:41 ` Aaron Ecay
  0 siblings, 1 reply; 12+ messages in thread
From: Kaushal Modi @ 2018-05-24 13:40 UTC (permalink / raw)
  To: emacs-org list

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

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 <summary> and </summary>
      ;;   ---
      ;;   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 </details> 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")
             ;;   ```</details>
             ;; A closing </p> tag is also added.. the opening <p>
             ;; tag is later added in the `str2' var if summary is
             ;; present, else in `str3' var.
             (str1 (replace-regexp-in-string "</details>\\'" "\n</p>\\&"
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 <p> 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 <summary> too, using "details
             ;; .details".
             (str2 (replace-regexp-in-string
                    "^\\(---\\)\n\\(.\\|\n\\)*\\'"
                    "</summary><p class=\"details\">"
                    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 "\\`<details>"
"\\&<summary>" str2)
                     (replace-regexp-in-string "\\`<details>" "\\&<p
class=\"details\">" str2)))
        (if is-open
            (replace-regexp-in-string "\\`\\(<details\\)>" "\\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 &mdash; 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

[-- Attachment #2: Type: text/html, Size: 4723 bytes --]

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

end of thread, other threads:[~2018-05-27 16:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24 13:40 RFC: Proposal for an Org Special Block for ox-html Kaushal Modi
2018-05-24 17:41 ` Aaron Ecay
2018-05-24 18:08   ` Kaushal Modi
2018-05-24 18:28     ` Kaushal Modi
2018-05-24 18:36     ` Aaron Ecay
2018-05-24 18:47       ` Kaushal Modi
2018-05-24 19:08         ` Aaron Ecay
2018-05-24 19:25           ` Kaushal Modi
2018-05-25 14:19             ` Aaron Ecay
2018-05-25 15:09               ` Kaushal Modi
2018-05-25 16:38                 ` Kaushal Modi
2018-05-27 16:21                 ` Aaron Ecay

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).