[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode eb42d39 7/8: Merge pull request #598 from jr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode eb42d39 7/8: Merge pull request #598 from jrblevin/pr-596 |
Date: |
Wed, 10 Feb 2021 01:57:12 -0500 (EST) |
branch: elpa/markdown-mode
commit eb42d39be2ba15c4870d404accb0f28ba356c749
Merge: 3ac7743 ec15e37
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #598 from jrblevin/pr-596
Improve #596
---
CHANGES.md | 2 ++
markdown-mode.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
tests/markdown-test.el | 15 +++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index 8ef39e4..5cca9e4 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -12,6 +12,7 @@
`markdown-disable-tooltip-prompt`.
- Introduce `markdown-ordered-list-enumeration` variable [GH-587][]
- Search wiki link under project
+ - Add `markdown-insert-gfm-foldable-block` function [GH-596][]
* Improvements:
- Correct indirect buffer's indentation in `markdown-edit-code-block`
[GH-375][]
@@ -65,6 +66,7 @@
[gh-584]: https://github.com/jrblevin/markdown-mode/issues/584
[gh-587]: https://github.com/jrblevin/markdown-mode/issues/587
[gh-590]: https://github.com/jrblevin/markdown-mode/pull/590
+ [gh-596]: https://github.com/jrblevin/markdown-mode/pull/596
# Markdown Mode 2.4
diff --git a/markdown-mode.el b/markdown-mode.el
index 6568b3d..9522da4 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -4435,6 +4435,49 @@ at the beginning of the block."
do (progn (when lang (markdown-gfm-add-used-language lang))
(goto-char (next-single-property-change (point) prop)))))))
+(defun markdown-insert-foldable-block ()
+ "Insert details disclosure element to make content foldable.
+If a region is active, wrap this region with the disclosure
+element. 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))
+ (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)
+ (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))
+ (let ((indent (current-indentation)))
+ (delete-horizontal-space :backward-only)
+ (markdown-ensure-blank-line-before)
+ (indent-to indent)
+ (insert details-open-tag "\n")
+ (insert summary-open-tag summary-close-tag "\n")
+ (insert details-close-tag)
+ (indent-to indent)
+ (markdown-ensure-blank-line-after)
+ (search-backward summary-close-tag)))))
+
;;; Footnotes =================================================================
@@ -5180,6 +5223,7 @@ Assumes match data is available for
`markdown-regex-italic'."
(propertize "C = GFM code" 'face 'markdown-code-face) ", "
(propertize "pre" 'face 'markdown-pre-face) ", "
(propertize "footnote" 'face 'markdown-footnote-text-face) ", "
+ (propertize "F = foldable" 'face 'markdown-bold-face) ", "
(propertize "q = blockquote" 'face 'markdown-blockquote-face) ", "
(propertize "h & 1-6 = heading" 'face 'markdown-header-face) ", "
(propertize "- = hr" 'face 'markdown-hr-face) ", "
@@ -5213,6 +5257,7 @@ Assumes match data is available for
`markdown-regex-italic'."
(define-key map (kbd "c") 'markdown-insert-code)
(define-key map (kbd "C") 'markdown-insert-gfm-code-block)
(define-key map (kbd "f") 'markdown-insert-footnote)
+ (define-key map (kbd "F") 'markdown-insert-foldable-block)
(define-key map (kbd "h") 'markdown-insert-header-dwim)
(define-key map (kbd "H") 'markdown-insert-header-setext-dwim)
(define-key map (kbd "i") 'markdown-insert-italic)
@@ -5524,6 +5569,7 @@ See also `markdown-mode-map'.")
["GFM Code Block" markdown-insert-gfm-code-block]
["Edit Code Block" markdown-edit-code-block
:enable (markdown-code-block-at-point-p)]
+ ["Foldable Block" markdown-insert-foldable-block]
"---"
["Blockquote Region" markdown-blockquote-region]
["Preformatted Region" markdown-pre-region]
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index e32ebb6..cba9b61 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -1324,6 +1324,21 @@ Detail: https://github.com/jrblevin/markdown-mode/issues"
(execute-kbd-macro (read-kbd-macro "M-x markdown-insert-link RET RET RET
RET"))
(should (string-equal (buffer-string) "[GNU](https://www.gnu.org/)")))))
+(ert-deftest test-markdown-insertion/foldable-block ()
+ "Test `markdown-insert-foldable-block'."
+ (markdown-test-string ""
+ (call-interactively 'markdown-insert-foldable-block)
+ (should (string= (buffer-string) "<details>\n<summary>
</summary>\n</details>"))
+ (should (looking-back "<summary>")))
+
+ (markdown-test-string "foo"
+ (push-mark (point) t t)
+ (end-of-line)
+ (should (use-region-p))
+ (call-interactively 'markdown-insert-foldable-block)
+ (should (string= (buffer-string) "<details>\n<summary>
</summary>\nfoo\n</details>"))
+ (should (looking-back "<summary>"))))
+
;;; Footnote tests:
(ert-deftest test-markdown-footnote/basic-end ()
- [nongnu] elpa/markdown-mode updated (3ac7743 -> 215ff35), ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode 8259a19 1/8: Add markdown-insert-gfm-foldable-block, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode e43c424 2/8: Update CHANGES.md, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode 94ea3c6 3/8: Fix CI issue, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode 3d4e3fc 4/8: Refactoring code, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode b2c4d9e 5/8: Add flows for using inserting foldable block, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode 215ff35 8/8: Fix wrong indentation in test file, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode ec15e37 6/8: Add tests about inserting foldable block, ELPA Syncer, 2021/02/10
- [nongnu] elpa/markdown-mode eb42d39 7/8: Merge pull request #598 from jrblevin/pr-596,
ELPA Syncer <=