@@ -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
0 commit comments