branch: elpa/markdown-mode
commit 038f0fb9789afafff99b7f23de107862dde113ee
Merge: 7659bc470d 4948549471
Author: Shohei YOSHIDA <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #878 from Hi-Angel/fix-uris-in-inline-code
Don't break inline-code rendering when there's a <foo:bar>
---
CHANGES.md | 2 ++
markdown-mode.el | 38 ++++++++++++++++++++++----------------
tests/markdown-test.el | 10 ++++++++++
3 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 58748f5ace..5b67b349ee 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -24,6 +24,7 @@
and `markdown-fontify-code-blocks-natively` together [GH-766][]
- Fix `markdown-fontify-whole-heading-line` regression [GH-848][]
- Fix using fundamental-mode issue when editting code block [GH-868][]
+ - Fix highlighting URL in angle brackes[GH-822][]
* Improvements:
- Apply url-unescape against URL in an inline link [GH-805][]
@@ -40,6 +41,7 @@
[gh-804]: https://github.com/jrblevin/markdown-mode/issues/804
[gh-805]: https://github.com/jrblevin/markdown-mode/issues/805
[gh-817]: https://github.com/jrblevin/markdown-mode/issues/817
+ [gh-822]: https://github.com/jrblevin/markdown-mode/issues/822
[gh-827]: https://github.com/jrblevin/markdown-mode/issues/827
[gh-834]: https://github.com/jrblevin/markdown-mode/issues/834
[gh-838]: https://github.com/jrblevin/markdown-mode/issues/838
diff --git a/markdown-mode.el b/markdown-mode.el
index f99897db4a..e69a94d0a5 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -1177,6 +1177,10 @@ escape character (see `markdown-match-escape').")
If POS is not given, use point instead."
(get-text-property (or pos (point)) 'markdown-comment))
+(defsubst markdown-in-inline-code-p (pos)
+ "Return non-nil if POS is in inline code."
+ (equal (get-text-property pos 'face) '(markdown-inline-code-face)))
+
(defun markdown--face-p (pos faces)
"Return non-nil if face of POS contain FACES."
(let ((face-prop (get-text-property pos 'face)))
@@ -8269,22 +8273,24 @@ Translate filenames using
`markdown-filename-translate-function'."
(defun markdown-fontify-angle-uris (last)
"Add text properties to angle URIs from point to LAST."
(when (markdown-match-angle-uris last)
- (let* ((url-start (match-beginning 2))
- (url-end (match-end 2))
- ;; Markup part
- (mp (list 'face 'markdown-markup-face
- 'invisible 'markdown-markup
- 'rear-nonsticky t
- 'font-lock-multiline t))
- ;; URI part
- (up (list 'keymap markdown-mode-mouse-map
- 'face 'markdown-plain-url-face
- 'mouse-face 'markdown-highlight-face
- 'font-lock-multiline t)))
- (dolist (g '(1 3))
- (add-text-properties (match-beginning g) (match-end g) mp))
- (add-text-properties url-start url-end up)
- t)))
+ (let ((url-start (match-beginning 2))
+ (url-end (match-end 2)))
+ (unless (or (markdown-in-inline-code-p url-start)
+ (markdown-in-inline-code-p url-end))
+ (let* (;; Markup part
+ (mp (list 'face 'markdown-markup-face
+ 'invisible 'markdown-markup
+ 'rear-nonsticky t
+ 'font-lock-multiline t))
+ ;; URI part
+ (up (list 'keymap markdown-mode-mouse-map
+ 'face 'markdown-plain-url-face
+ 'mouse-face 'markdown-highlight-face
+ 'font-lock-multiline t)))
+ (dolist (g '(1 3))
+ (add-text-properties (match-beginning g) (match-end g) mp))
+ (add-text-properties url-start url-end up)
+ t)))))
(defun markdown-fontify-plain-uris (last)
"Add text properties to plain URLs from point to LAST."
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 83059bf7bc..ff02dd8188 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -2478,6 +2478,16 @@ See GH-275."
(markdown-test-range-has-face 12 12 'markdown-markup-face)
(markdown-test-range-has-face 18 18 'markdown-markup-face)))
+(ert-deftest test-markdown-font-lock/ignore-uri-in-inline-code ()
+ "Avoid rendering URIs inside inline code."
+ (markdown-test-string
+ "`<http:foo>` t `a <http:bar> b` <http:`bar>` t `<http`:bar>`<http:`bar>"
+ (markdown-test-range-has-face 2 11 'markdown-inline-code-face)
+ (markdown-test-range-has-face 17 30 'markdown-inline-code-face)
+ (markdown-test-range-has-face 40 43 'markdown-inline-code-face)
+ (markdown-test-range-has-face 49 53 'markdown-inline-code-face)
+ (markdown-test-range-has-face 61 66 'markdown-inline-code-face)))
+
(ert-deftest test-markdown-font-lock/italics-in-reference-definitions ()
"Test not matching italics in reference definitions across lines."
(markdown-test-string