branch: elpa/markdown-mode commit eb4b02e40ca0b2a843d4424f20db49012e4598c4 Merge: 819ab2a212 ee9d6de1d2 Author: Joe Reinhart <joseph.reinh...@gmail.com> Commit: Joe Reinhart <joseph.reinh...@gmail.com>
Merge branch 'master' into jayemar/toggle-hiding-of-wiki-links --- CHANGES.md | 4 ++++ markdown-mode.el | 61 ++++++++++++++++++++++++++++++++++++++------------ tests/markdown-test.el | 22 ++++++++++++++++++ 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 58748f5ace..1c71afbba7 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][] @@ -34,12 +35,14 @@ - Resolve style sheets in `markdown-css-paths` relative to the Markdown file (if the path starts with `./` or `../`) [GH-855][] [GH-870][] - Don't insert list item in code block [GH-841][] + - Don't set mouse face if `markdown-mouse-follow-link` is nil [GH-879][] [gh-780]: https://github.com/jrblevin/markdown-mode/issues/780 [gh-802]: https://github.com/jrblevin/markdown-mode/issues/802 [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 @@ -50,6 +53,7 @@ [gh-855]: https://github.com/jrblevin/markdown-mode/issues/855 [gh-868]: https://github.com/jrblevin/markdown-mode/issues/868 [gh-870]: https://github.com/jrblevin/markdown-mode/issues/870 + [gh-879]: https://github.com/jrblevin/markdown-mode/issues/879 # Markdown Mode 2.6 diff --git a/markdown-mode.el b/markdown-mode.el index e9dd0c43e6..6e0313ca9d 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -1176,6 +1176,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))) @@ -8195,7 +8199,26 @@ Translate filenames using `markdown-filename-translate-function'." (title-start (match-beginning 7)) (title-end (match-end 7)) (title (match-string-no-properties 7)) - (url-char (markdown--first-displayable markdown-url-compose-char))) + ;; Markup part + (mp (list 'invisible 'markdown-markup + 'rear-nonsticky t + 'font-lock-multiline t)) + ;; Link part (without face) + (lp (list 'keymap markdown-mode-mouse-map + 'font-lock-multiline t + 'help-echo (if title (concat title "\n" url) url))) + ;; URL part + (up (list 'keymap markdown-mode-mouse-map + 'invisible 'markdown-markup + 'font-lock-multiline t)) + ;; URL composition character + (url-char (markdown--first-displayable markdown-url-compose-char)) + ;; Title part + (tp (list 'invisible 'markdown-markup + 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq lp (append lp '(mouse-face 'markdown-highlight-face))) + (setq up (append up '(mouse-face 'markdown-highlight-face)))) (dolist (g '(1 2 4 5 8)) (when (match-end g) (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) @@ -8223,7 +8246,6 @@ Translate filenames using `markdown-filename-translate-function'." (ref-end (match-end 6)) ;; Link properties (lp (list 'keymap markdown-mode-mouse-map - 'mouse-face 'markdown-highlight-face 'font-lock-multiline t 'help-echo (lambda (_ __ pos) (save-match-data @@ -8236,6 +8258,8 @@ Translate filenames using `markdown-filename-translate-function'." ;; Reference properties (rp (list 'invisible 'markdown-markup 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq lp (append lp '(mouse-face markdown-highlight-face)))) (dolist (g '(1 2 4 5 8)) (when (match-end g) (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) @@ -8322,17 +8346,25 @@ 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)) - ;; URI properties - (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) markdown--markup-props)) - (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 + 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq up (append up '(mouse-face markdown-highlight-face)))) + (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." @@ -8341,9 +8373,10 @@ Translate filenames using `markdown-filename-translate-function'." (end (match-end 0)) (props (list 'keymap markdown-mode-mouse-map 'face 'markdown-plain-url-face - 'mouse-face 'markdown-highlight-face 'rear-nonsticky t 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq props (append props '(mouse-face markdown-highlight-face)))) (add-text-properties start end props) t))) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 6f3703538f..79b8831552 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 @@ -3189,6 +3199,18 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/716" (markdown-test-range-has-face (match-beginning 0) (1- (match-end 0)) 'markdown-markup-face) (markdown-test-range-has-face (match-beginning 0) (1- (match-end 0)) 'markdown-table-face)))) +(ert-deftest test-markdown-font-lock/mouse-face-in-link () + "Test links of mouse face. +Detail: https://github.com/jrblevin/markdown-mode/issues/879" + (markdown-test-string "[foo](https://example.com)" + (should (get-text-property 7 'mouse-face)) + (should (get-text-property 25 'mouse-face))) + + (let ((markdown-mouse-follow-link nil)) + (markdown-test-string "[foo](https://example.com)" + (should-not (get-text-property 7 'mouse-face)) + (should-not (get-text-property 25 'mouse-face))))) + (ert-deftest test-markdown-font-lock/comment-hanging-indent () "Test comments with hanging indentation." (markdown-test-string "<!-- This comment has\n hanging indentation -->"