[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode 137696f 8/8: Merge branch 'pr-581'
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode 137696f 8/8: Merge branch 'pr-581' |
Date: |
Wed, 6 Jan 2021 19:57:13 -0500 (EST) |
branch: elpa/markdown-mode
commit 137696f1b3b3d8b028995d933d555f1313bc5ae5
Merge: 0085875 ec6ae58
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: Shohei YOSHIDA <syohex@gmail.com>
Merge branch 'pr-581'
---
CHANGES.md | 1 +
README.md | 6 ++++
markdown-mode.el | 77 ++++++++++++++++++++++++++++----------------------
tests/markdown-test.el | 7 +++++
4 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 788cd1e..d3ed601 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,7 @@
- Clean up Makefile
- Support to display local image with percent encoding file path
- Add ability to resize inline image display
(`markdown-toggle-inline-images`) without Imagemagick installed in the computer
(emulating Org Mode)
+ - Support including braces around the language specification in GFM code
blocks
* Bug fixes:
- Fix remaining flyspell overlay in code block or comment issue
[GH-311][]
diff --git a/README.md b/README.md
index bd4e891..216e180 100644
--- a/README.md
+++ b/README.md
@@ -991,6 +991,12 @@ by `markdown-mode` and `gfm-mode` as described below.
region will be placed inside the code block. You will be
prompted for the name of the language, but may press enter to
continue without naming a language.
+
+ In addition, in `gfm-mode`, GFM code blocks can be inserted via the
+ option `markdown-gfm-use-electric-backquote`. If the option
+ `markdown-code-block-braces` is set to `t`, code blocks inserted with
+ <kbd>C-c C-s C</kbd> or electric backquotes will include braces ("{}")
+ around the language attributes.
* **Strikethrough:** Strikethrough text is supported in both
`markdown-mode` and `gfm-mode`. It can be inserted (and toggled)
diff --git a/markdown-mode.el b/markdown-mode.el
index 64e5ac0..4d9ab78 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -4301,6 +4301,11 @@ opening code fence and an info string."
:safe #'natnump
:package-version '(markdown-mode . "2.3"))
+(defcustom markdown-code-block-braces nil
+ "When non-nil, automatically insert braces for GFM code blocks."
+ :group 'markdown
+ :type 'boolean)
+
(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
@@ -4321,45 +4326,49 @@ code block in an indirect buffer after insertion."
(quit "")))
current-prefix-arg))
(unless (string= lang "") (markdown-gfm-add-used-language lang))
- (when (> (length lang) 0)
+ (when (and (> (length lang) 0)
+ (not markdown-code-block-braces))
(setq lang (concat (make-string markdown-spaces-after-code-fence ?\s)
lang)))
- (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 ```
- ;; should go on its own line
- (unless (looking-back "\n" nil)
- (newline))
+ (let ((gfm-open-brace (if markdown-code-block-braces "{" ""))
+ (gfm-close-brace (if markdown-code-block-braces "}" "")))
+ (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 ```
+ ;; should go on its own line
+ (unless (looking-back "\n" nil)
+ (newline))
+ (indent-to indent)
+ (insert "```")
+ (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 "```" gfm-open-brace lang gfm-close-brace)
+ (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 "```" gfm-open-brace lang gfm-close-brace "\n")
+ (indent-to indent)
+ (unless edit (insert ?\n))
(indent-to indent)
(insert "```")
(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 "```" lang)
- (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 "```" lang "\n")
- (indent-to indent)
- (unless edit (insert ?\n))
- (indent-to indent)
- (insert "```")
- (markdown-ensure-blank-line-after)
- (markdown-syntax-propertize-fenced-block-constructs start-bol (point)))
- (end-of-line 0)
- (when edit (markdown-edit-code-block))))
+ (markdown-syntax-propertize-fenced-block-constructs start-bol (point)))
+ (end-of-line 0)
+ (when edit (markdown-edit-code-block)))))
(defun markdown-code-block-lang (&optional pos-prop)
"Return the language name for a GFM or tilde fenced code block.
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 99b9ad3..a6b200f 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -6185,6 +6185,13 @@ Details:
https://github.com/jrblevin/markdown-mode/issues/534"
(should (equal (buffer-substring-no-properties (point) (point-max))
"\n bar\n ```\n\n"))))
+(ert-deftest test-markdown-gfm/markdown-code-block-braces ()
+ "Test `markdown-gfm-use-electric-backquote'."
+ (markdown-test-string-gfm ""
+ (let ((markdown-code-block-braces t))
+ (markdown-insert-gfm-code-block "elisp")
+ (should (equal (buffer-string) "```{elisp}\n\n```")))))
+
(ert-deftest test-markdown-gfm/gfm-parse-buffer-for-languages ()
"Parse buffer for existing languages for `markdown-gfm-used-languages' test."
(markdown-test-string-gfm "``` MADEUP\n\n```\n```
LANGUAGES\n\n```\n```MaDeUp\n\n```\n```\n\n```\n``` \n\n```\n"
- [nongnu] elpa/markdown-mode updated (e250a84 -> 137696f), ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode fc733be 1/8: feat: Add resize inline image without imagemagick, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 0085875 4/8: Merge pull request #579 from nobiot/feat/inline-image-size-no-imagemagick, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 6724a2c 5/8: Added optional support for inserting braces in GFM code block header, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 6f97180 3/8: Update CHANGELOG, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode da7b9df 2/8: Update CHANGELOG, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode d5106ff 6/8: Add unit test for markdown code block braces, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode ec6ae58 7/8: Merge remote-tracking branch 'origin/master' into pr-581, ELPA Syncer, 2021/01/06
- [nongnu] elpa/markdown-mode 137696f 8/8: Merge branch 'pr-581',
ELPA Syncer <=