[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode 7c751d85c3 1/3: Don't treat backslashes as e
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode 7c751d85c3 1/3: Don't treat backslashes as escapes inside literal blocks; resolves #766 |
Date: |
Sun, 21 May 2023 22:02:14 -0400 (EDT) |
branch: elpa/markdown-mode
commit 7c751d85c3b53ee68e7090afca3cad6010d49837
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Don't treat backslashes as escapes inside literal blocks; resolves #766
---
markdown-mode.el | 37 ++++++++++++++++++++++++++++++++++++-
tests/markdown-test.el | 16 ++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/markdown-mode.el b/markdown-mode.el
index 9d7bb31d9c..2a89d793a5 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -1105,6 +1105,29 @@ Group 4 matches the text inside the delimiters.")
'markdown-metadata-markup nil)
"Property list of all Markdown syntactic properties.")
+(defvar markdown-literal-faces
+ '(markdown-inline-code-face
+ markdown-pre-face
+ markdown-math-face
+ markdown-url-face
+ markdown-plain-url-face
+ markdown-language-keyword-face
+ markdown-language-info-face
+ markdown-metadata-key-face
+ markdown-metadata-value-face
+ markdown-html-entity-face
+ markdown-html-tag-name-face
+ markdown-html-tag-delimiter-face
+ markdown-html-attr-name-face
+ markdown-html-attr-value-face
+ markdown-reference-face
+ markdown-footnote-marker-face
+ markdown-line-break-face
+ markdown-comment-face)
+ "A list of markdown-mode faces that contain literal text.
+Literal text treats backslashes literally, rather than as an
+escape character (see `markdown-match-escape').")
+
(defsubst markdown-in-comment-p (&optional pos)
"Return non-nil if POS is in a comment.
If POS is not given, use point instead."
@@ -2220,7 +2243,7 @@ Depending on your font, some reasonable choices are:
(4 'markdown-highlighting-face)
(5 markdown-markup-properties)))
(,markdown-regex-line-break . (1 'markdown-line-break-face prepend))
- (,markdown-regex-escape . ((1 markdown-markup-properties prepend)))
+ (markdown-match-escape . ((1 markdown-markup-properties prepend)))
(markdown-fontify-sub-superscripts)
(markdown-match-inline-attributes . ((0 markdown-markup-properties
prepend)))
(markdown-match-leanpub-sections . ((0 markdown-markup-properties)))
@@ -2952,6 +2975,18 @@ When FACELESS is non-nil, do not return matches where
faces have been applied."
(when markdown-enable-highlighting-syntax
(re-search-forward markdown-regex-highlighting last t)))
+(defun markdown-match-escape (last)
+ "Match escape characters (backslashes) from point to LAST.
+Backlashes only count as escape characters outside of literal
+regions (e.g. code blocks). See `markdown-literal-faces'."
+ (catch 'found
+ (while (search-forward-regexp markdown-regex-escape last t)
+ (let* ((face (get-text-property (match-beginning 1) 'face))
+ (face-list (if (listp face) face (list face))))
+ ;; Ignore any backslashes with a literal face.
+ (unless (cl-intersection face-list markdown-literal-faces)
+ (throw 'found t))))))
+
(defun markdown-match-math-generic (regex last)
"Match REGEX from point to LAST.
REGEX is either `markdown-regex-math-inline-single' for matching
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index dea5d98075..3468dee8ee 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -2144,6 +2144,22 @@ See GH-245."
(should (invisible-p (point)))
(should-not (invisible-p (1+ (point))))))
+(ert-deftest test-markdown-markup-hiding/code-2 ()
+ "Test hiding markup for inline code with backslashes."
+ (markdown-test-file "inline.text"
+ (goto-char 460)
+ (should (looking-at "`C-h C-\\\\`"))
+ (markdown-test-range-has-property (point) (point) 'invisible
'markdown-markup)
+ (should-not (invisible-p (point)))
+ (should-not (invisible-p (+ 1 (point))))
+ (should-not (invisible-p (+ 7 (point))))
+ (should-not (invisible-p (+ 8 (point))))
+ (markdown-toggle-markup-hiding t)
+ (should (invisible-p (point)))
+ (should-not (invisible-p (+ 1 (point))))
+ (should-not (invisible-p (+ 7 (point))))
+ (should (invisible-p (+ 8 (point))))))
+
(ert-deftest test-markdown-markup-hiding/kbd-1 ()
"Test hiding markup for <kbd> tags."
(markdown-test-string "<kbd>C-c C-x C-m</kbd>"