From 704b6e963f4ec9c33f78075a810ed8c9e56a905d Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Fri, 25 May 2018 13:06:49 -0400 Subject: [PATCH] Optimize the details/summary code --- ox-blackfriday.el | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/ox-blackfriday.el b/ox-blackfriday.el index 67efcc6..b72ae50 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -705,27 +705,20 @@ This function is adapted from `org-html-special-block'." ;; #+end_summary ;; Here are the details. ;; #+end_details - (setq contents - (let* (;; A closing

tag is added at the end.. the - ;; opening

tag for that is later added in - ;; the `str2' var. Insert a newline before - ;; that tag for the reason explained below - ;; using the emacs-lisp Markdown code block. - (str1 (concat contents "\n

")) - ;; Detect the summary closing tag "". - ;; If found, add the opening

tag with - ;; "details" class after that, so that CSS - ;; rules can be set specific to the details - ;; portion using "details .details". - (str2 (replace-regexp-in-string - "

\\(?:.\\|\n\\)*" - "\\&\n

" - str1)) - (has-summary (not (string= str1 str2)))) - ;; (message "[DBG details/summary]: is-open:%S `%s' `%s'" is-open str1 str2) - (unless has-summary - (setq str2 (concat "

" str1))) - str2)) + (let ((p-open "

")) + (setq contents + (concat + ;; Wrap the "details" portion in the

tag + ;; with '

..

'. With that, + ;; CSS rules can be set specific to that details + ;; portion using "details .details". + (if (string-match "\\(?1:\\(?:.\\|\n\\)*\\)" contents) ;If summary exists + (replace-match (format "\\1\n%s" p-open) nil nil contents 1) + (concat p-open contents)) + ;; A newline is inserted before the closing

+ ;; tag for the reason explained below using the + ;; emacs-lisp Markdown code block. + "\n

"))) ;; Insert the "open" attribute only if user has ":open t" in ;; "#+attr_html". (when (org-string-nw-p attr-str)