branch: elpa/markdown-mode commit 0f6ccf0529aba89e55e02ec64ddfac578948dfed Author: Konstantin Kharlamov <hi-an...@yandex.ru> Commit: Konstantin Kharlamov <hi-an...@yandex.ru>
Don't break inline-code rendering when there's a <foo:bar> A Markdown like `value=<addr:port>` results in `<addr:port>` suddenly refusing to highlight. This is because the mode recognizes this as an angle URL. Generally speaking, a URL (even if actual one) is not expected to be rendered inside inline code-blocks, so this commit adds a test for whether start or end is in inline block, to avoid breaking rendering. A test for this is added as well. Fixes: https://github.com/jrblevin/markdown-mode/issues/822 --- markdown-mode.el | 38 ++++++++++++++++++++++---------------- tests/markdown-test.el | 10 ++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) 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