branch: elpa/markdown-mode commit d51c469133d220823cc6ab50ff8e8743ed6e42fb Merge: fc4fff89bae 9106f5aa182 Author: Shohei YOSHIDA <syo...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #918 from jrblevin/improve-link-parsing Improve inline link highlighting --- CHANGES.md | 2 ++ markdown-mode.el | 15 ++++++++++++--- tests/markdown-test.el | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6ec0fd4df6d..79221118fbf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ - Angle URL fontify issue which was introduced by [GH-861][] [GH-895][] - Fix list item bound calculation when tab indentation is used [GH-904][] - Fix `markdown-heading-at-point` at the end of line [GH-912][] + - Catch an exception when `scan-sexp` fails [GH-917][] * Improvements: - Support drag and drop features on Windows and multiple files' drag and drop @@ -32,6 +33,7 @@ [gh-904]: https://github.com/jrblevin/markdown-mode/issues/904 [gh-910]: https://github.com/jrblevin/markdown-mode/issues/910 [gh-912]: https://github.com/jrblevin/markdown-mode/issues/912 + [gh-917]: https://github.com/jrblevin/markdown-mode/issues/917 # Markdown Mode 2.7 diff --git a/markdown-mode.el b/markdown-mode.el index 77f9bf55cb6..ec886720abc 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -3282,11 +3282,18 @@ processed elements." (markdown-end-of-text-block) (point)))) ;; Move over balanced expressions to closing right bracket. - ;; Catch unbalanced expression errors and return nil. + ;; Catch unbalanced expression errors, then try to search right bracket manually. (first-end (condition-case nil (and (goto-char first-begin) (scan-sexps (point) 1)) - (error nil))) + (error + (save-match-data + (let ((last (match-end 4)) + ok end-pos) + (while (and (not ok) (search-forward "]" last t)) + (unless (= (char-before (1- (point))) ?\\) + (setq ok t end-pos (point)))) + end-pos))))) ;; Continue with point at CONT-POINT upon failure. (cont-point (min (1+ first-begin) last)) second-begin second-end url-begin url-end @@ -8183,7 +8190,9 @@ Value is a list of elements describing the link: url (match-string-no-properties 6)) ;; consider nested parentheses ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link - (let* ((close-pos (scan-sexps (match-beginning 5) 1)) + (let* ((close-pos (condition-case nil + (scan-sexps (match-beginning 5) 1) + (error (match-end 0)))) (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos))))) (setq end close-pos) ;; A link can contain spaces if it is wrapped with angle brackets diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 9d8ba2a610c..f843730d01e 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -3188,7 +3188,15 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/409" (markdown-test-range-has-face 2 24 'markdown-link-face) (markdown-test-range-has-face 25 26 'markdown-markup-face) (markdown-test-range-has-face 27 40 'markdown-url-face) - (markdown-test-range-has-face 41 41 'markdown-markup-face))) + (markdown-test-range-has-face 41 41 'markdown-markup-face)) + + ;; https://github.com/jrblevin/markdown-mode/issues/917 + (markdown-test-string "[(foo](http://foo.com)" + (markdown-test-range-has-face 1 1 'markdown-markup-face) + (markdown-test-range-has-face 2 5 'markdown-link-face) + (markdown-test-range-has-face 6 7 'markdown-markup-face) + (markdown-test-range-has-face 8 21 'markdown-url-face) + (markdown-test-range-has-face 22 22 'markdown-markup-face))) (ert-deftest test-markdown-font-lock/pre-comment () "Test comments inside of a pre block."