markdown-mode icon indicating copy to clipboard operation
markdown-mode copied to clipboard

Display both inline images and image markdown (.emacs override)

Open kcyarn opened this issue 7 years ago • 5 comments

Toggling inline images so I can edit the alt text was a pain. The existing markdown-toggle-inline-images works great for a half dozen images. Toggling the images on and off to edit each alt text in a document with ninety-eight images...not fun. Around image twenty, I made the following alteration to my .emacs file.

Instead of displaying the image instead of the markdown code, the image is now displayed two new lines under the image markdown code. A minor thing and probably not something for inclusion in the mode. Still, I thought someone else might find this useful.

(load "markdown-mode")

;; Override Markdown Mode's image overlays so the image markdown code and the image are both visible!
(eval-after-load "markdown-mode"
  '(defun markdown-display-inline-images ()
  "Add inline image overlays to image links in the buffer.
This can be toggled with `markdown-toggle-inline-images'
or \\[markdown-toggle-inline-images]."
  (interactive)
  (unless (display-images-p)
    (error "Cannot show images"))
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (while (re-search-forward markdown-regex-link-inline nil t)
        (let ((start (match-beginning 0))
              (end (match-end 0))
              (file (match-string-no-properties 6)))
          (when (file-exists-p file)
            (let* ((abspath (if (file-name-absolute-p file)
                                file
                              (concat default-directory file)))
                   (image
                    (if (and markdown-max-image-size
                             (image-type-available-p 'imagemagick))
                        (create-image
                         abspath 'imagemagick nil
                         :max-width (car markdown-max-image-size)
                         :max-height (cdr markdown-max-image-size))
                      (create-image abspath))))
              (when image
                (setq newStart (+ end ))
                (setq newEnd (+ end 1))
                (let ((ov (make-overlay newStart newEnd)))
                  (message "%s" newEnd)
                  (overlay-put ov 'display image)
                  (overlay-put ov 'face 'default)
                  (overlay-put ov 'before-string "\n\n")
                  (push ov markdown-inline-image-overlays))))))))))
)

kcyarn avatar Apr 04 '18 22:04 kcyarn

Thanks, nice idea. I'll file this as a feature request and try it out when I get a chance.

jrblevin avatar Jun 15 '18 20:06 jrblevin

Any news on this?

Evidlo avatar Aug 11 '20 07:08 Evidlo

Sorry, there is no update.

syohex avatar Aug 11 '20 12:08 syohex

It will be great if this feature is implemented!

jcs090218 avatar Dec 26 '20 08:12 jcs090218

Needed this as well. I implemented it and isolated the relevant bits from the original markdown-display-inline-images. Could open a PR if this helps.

piiil avatar Mar 03 '24 21:03 piiil