markdown-mode
markdown-mode copied to clipboard
Display both inline images and image markdown (.emacs override)
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))))))))))
)
Thanks, nice idea. I'll file this as a feature request and try it out when I get a chance.
Any news on this?
Sorry, there is no update.
It will be great if this feature is implemented!
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.