emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/markdown-mode 8259a19 1/8: Add markdown-insert-gfm-foldabl


From: ELPA Syncer
Subject: [nongnu] elpa/markdown-mode 8259a19 1/8: Add markdown-insert-gfm-foldable-block
Date: Wed, 10 Feb 2021 01:57:10 -0500 (EST)

branch: elpa/markdown-mode
commit 8259a19907c7426e5bb6d5d734bfb8da38c41df5
Author: Sibi Prabakaran <sibi@psibi.in>
Commit: Sibi Prabakaran <sibi@psibi.in>

    Add markdown-insert-gfm-foldable-block
    
    This can be used for adding a collapsible content. Works in both
    github and gitlab from my teseting.
    
    More details here: https://github.com/jrblevin/markdown-mode/issues/595
---
 markdown-mode.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/markdown-mode.el b/markdown-mode.el
index 6568b3d..e1b2e13 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -4332,6 +4332,56 @@ opening code fence and an info string."
   :group 'markdown
   :type 'boolean)
 
+(defun markdown-insert-gfm-foldable-block ()
+  "Insert details disclosure element which creates a disclosure
+  widget that can be used for having foldable content. More
+  detais here 
'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details'"
+  (interactive
+   (let ((details-open-tag "<details>")
+         (details-close-tag "</details>")
+         (summary-open-tag "<summary>")
+         (summary-close-tag " </summary>"))
+     (if (use-region-p)
+         (let* ((b (region-beginning)) (e (region-end)) end
+                (indent (progn (goto-char b) (current-indentation))))
+           (goto-char e)
+           ;; if we're on a blank line, don't newline, otherwise the tags
+           ;; should go on its own line
+           (unless (looking-back "\n" nil)
+             (newline))
+           (indent-to indent)
+           (insert details-close-tag)
+           (markdown-ensure-blank-line-after)
+           (setq end (point))
+           (goto-char b)
+           ;; if we're on a blank line, insert the quotes here, otherwise
+           ;; add a new line first
+           (unless (looking-at-p "\n")
+             (newline)
+             (forward-line -1))
+           (markdown-ensure-blank-line-before)
+           (indent-to indent)
+           (insert details-open-tag "\n")
+           (insert summary-open-tag summary-close-tag)
+           (search-backward summary-close-tag)
+           (markdown-syntax-propertize-fenced-block-constructs (point-at-bol) 
end))
+       (let ((indent (current-indentation))
+             start-bol)
+         (delete-horizontal-space :backward-only)
+         (markdown-ensure-blank-line-before)
+         (indent-to indent)
+         (setq start-bol (point-at-bol))
+         (insert details-open-tag "\n")
+         (insert summary-open-tag summary-close-tag "\n")
+         (insert details-close-tag "\n")
+         (indent-to indent)
+         (markdown-ensure-blank-line-after)
+         (markdown-syntax-propertize-fenced-block-constructs start-bol (point))
+         (search-backward summary-close-tag))
+       )
+     )
+   ))
+
 (defun markdown-insert-gfm-code-block (&optional lang edit)
   "Insert GFM code block for language LANG.
 If LANG is nil, the language will be queried from user.  If a



reply via email to

[Prev in Thread] Current Thread [Next in Thread]