Skip to content

Commit 9106f5a

Browse files
committed
Improve inline link highlighting
1 parent fc4fff8 commit 9106f5a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Angle URL fontify issue which was introduced by [GH-861][] [GH-895][]
1717
- Fix list item bound calculation when tab indentation is used [GH-904][]
1818
- Fix `markdown-heading-at-point` at the end of line [GH-912][]
19+
- Catch an exception when `scan-sexp` fails [GH-917][]
1920

2021
* Improvements:
2122
- Support drag and drop features on Windows and multiple files' drag and drop
@@ -32,6 +33,7 @@
3233
[gh-904]: https://github.com/jrblevin/markdown-mode/issues/904
3334
[gh-910]: https://github.com/jrblevin/markdown-mode/issues/910
3435
[gh-912]: https://github.com/jrblevin/markdown-mode/issues/912
36+
[gh-917]: https://github.com/jrblevin/markdown-mode/issues/917
3537

3638
# Markdown Mode 2.7
3739

markdown-mode.el

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,11 +3282,18 @@ processed elements."
32823282
(markdown-end-of-text-block)
32833283
(point))))
32843284
;; Move over balanced expressions to closing right bracket.
3285-
;; Catch unbalanced expression errors and return nil.
3285+
;; Catch unbalanced expression errors, then try to search right bracket manually.
32863286
(first-end (condition-case nil
32873287
(and (goto-char first-begin)
32883288
(scan-sexps (point) 1))
3289-
(error nil)))
3289+
(error
3290+
(save-match-data
3291+
(let ((last (match-end 4))
3292+
ok end-pos)
3293+
(while (and (not ok) (search-forward "]" last t))
3294+
(unless (= (char-before (1- (point))) ?\\)
3295+
(setq ok t end-pos (point))))
3296+
end-pos)))))
32903297
;; Continue with point at CONT-POINT upon failure.
32913298
(cont-point (min (1+ first-begin) last))
32923299
second-begin second-end url-begin url-end
@@ -8183,7 +8190,9 @@ Value is a list of elements describing the link:
81838190
url (match-string-no-properties 6))
81848191
;; consider nested parentheses
81858192
;; if link target contains parentheses, (match-end 0) isn't correct end position of the link
8186-
(let* ((close-pos (scan-sexps (match-beginning 5) 1))
8193+
(let* ((close-pos (condition-case nil
8194+
(scan-sexps (match-beginning 5) 1)
8195+
(error (match-end 0))))
81878196
(destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos)))))
81888197
(setq end close-pos)
81898198
;; A link can contain spaces if it is wrapped with angle brackets

tests/markdown-test.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3188,7 +3188,15 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/409"
31883188
(markdown-test-range-has-face 2 24 'markdown-link-face)
31893189
(markdown-test-range-has-face 25 26 'markdown-markup-face)
31903190
(markdown-test-range-has-face 27 40 'markdown-url-face)
3191-
(markdown-test-range-has-face 41 41 'markdown-markup-face)))
3191+
(markdown-test-range-has-face 41 41 'markdown-markup-face))
3192+
3193+
;; https://github.com/jrblevin/markdown-mode/issues/917
3194+
(markdown-test-string "[(foo](http://foo.com)"
3195+
(markdown-test-range-has-face 1 1 'markdown-markup-face)
3196+
(markdown-test-range-has-face 2 5 'markdown-link-face)
3197+
(markdown-test-range-has-face 6 7 'markdown-markup-face)
3198+
(markdown-test-range-has-face 8 21 'markdown-url-face)
3199+
(markdown-test-range-has-face 22 22 'markdown-markup-face)))
31923200

31933201
(ert-deftest test-markdown-font-lock/pre-comment ()
31943202
"Test comments inside of a pre block."

0 commit comments

Comments
 (0)