@@ -8449,6 +8449,33 @@ or \\[markdown-toggle-inline-images]."
8449
8449
(mapc #'delete-overlay markdown-inline-image-overlays)
8450
8450
(setq markdown-inline-image-overlays nil))
8451
8451
8452
+ (defcustom markdown-display-remote-images nil
8453
+ "If non-nil, download and display remote images.
8454
+ See also `markdown-inline-image-overlays'.
8455
+
8456
+ Only image URLs specified with a protocol listed in
8457
+ `markdown-remote-image-protocols' are displayed."
8458
+ :group 'markdown
8459
+ :type 'boolean)
8460
+
8461
+ (defcustom markdown-remote-image-protocols '("https")
8462
+ "List of protocols to use to download remote images.
8463
+ See also `markdown-display-remote-images'."
8464
+ :group 'markdown
8465
+ :type '(repeat string))
8466
+
8467
+ (defvar markdown--remote-image-cache
8468
+ (make-hash-table :test 'equal)
8469
+ "A map from URLs to image paths.")
8470
+
8471
+ (defun markdown--get-remote-image (url)
8472
+ "Retrieve the image path for a given URL."
8473
+ (or (gethash url markdown--remote-image-cache)
8474
+ (let ((dl-path (make-temp-file "markdown-mode--image")))
8475
+ (require 'url)
8476
+ (url-copy-file url dl-path t)
8477
+ (puthash url dl-path markdown--remote-image-cache))))
8478
+
8452
8479
(defun markdown-display-inline-images ()
8453
8480
"Add inline image overlays to image links in the buffer.
8454
8481
This can be toggled with `markdown-toggle-inline-images'
@@ -8466,24 +8493,29 @@ or \\[markdown-toggle-inline-images]."
8466
8493
(end (match-end 0))
8467
8494
(file (match-string-no-properties 6)))
8468
8495
(when (and imagep
8469
- (not (zerop (length file)))
8470
- (file-exists-p file))
8471
- (let* ((abspath (if (file-name-absolute-p file)
8472
- file
8473
- (concat default-directory file)))
8474
- (image
8475
- (if (and markdown-max-image-size
8476
- (image-type-available-p 'imagemagick))
8477
- (create-image
8478
- abspath 'imagemagick nil
8479
- :max-width (car markdown-max-image-size)
8480
- :max-height (cdr markdown-max-image-size))
8481
- (create-image abspath))))
8482
- (when image
8483
- (let ((ov (make-overlay start end)))
8484
- (overlay-put ov 'display image)
8485
- (overlay-put ov 'face 'default)
8486
- (push ov markdown-inline-image-overlays))))))))))
8496
+ (not (zerop (length file))))
8497
+ (unless (file-exists-p file)
8498
+ (when (and markdown-display-remote-images
8499
+ (member (downcase (url-type (url-generic-parse-url file)))
8500
+ markdown-remote-image-protocols))
8501
+ (setq file (markdown--get-remote-image file))))
8502
+ (when (file-exists-p file)
8503
+ (let* ((abspath (if (file-name-absolute-p file)
8504
+ file
8505
+ (concat default-directory file)))
8506
+ (image
8507
+ (if (and markdown-max-image-size
8508
+ (image-type-available-p 'imagemagick))
8509
+ (create-image
8510
+ abspath 'imagemagick nil
8511
+ :max-width (car markdown-max-image-size)
8512
+ :max-height (cdr markdown-max-image-size))
8513
+ (create-image abspath))))
8514
+ (when image
8515
+ (let ((ov (make-overlay start end)))
8516
+ (overlay-put ov 'display image)
8517
+ (overlay-put ov 'face 'default)
8518
+ (push ov markdown-inline-image-overlays)))))))))))
8487
8519
8488
8520
(defun markdown-toggle-inline-images ()
8489
8521
"Toggle inline image overlays in the buffer."
0 commit comments