emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: emacs-org list <emacs-orgmode@gnu.org>
Subject: RFC: Proposal for an Org Special Block for ox-html
Date: Thu, 24 May 2018 09:40:30 -0400	[thread overview]
Message-ID: <CAFyQvY2YoLDpM9PWLV86FwvPOVkuxg9O8KdryG3z=5QRm7Aujg@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2018-05-24 13:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 13:40 Kaushal Modi [this message]
2018-05-24 17:41 ` RFC: Proposal for an Org Special Block for ox-html 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFyQvY2YoLDpM9PWLV86FwvPOVkuxg9O8KdryG3z=5QRm7Aujg@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).