Skip to content

enable to preview with relative images. #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -7663,6 +7663,16 @@ or remove markup."

;;; Commands ==================================================================

(defun markdown--replace-rel2abs (output-buffer-name)
"Convert relative image URLs to absolute paths in OUTPUT-BUFFER-NAME."
(let ((buf (get-buffer-create output-buffer-name))
(base-path default-directory))
(with-current-buffer buf
(goto-char (point-min))
(while (re-search-forward "<img src=\"\\(\\.[^\"]+\\)" nil t)
(let ((arbitrary-name (match-string 1)))
(replace-match (concat "<img src=\"" (expand-file-name arbitrary-name base-path) nil nil)))))))

(defun markdown (&optional output-buffer-name)
"Run `markdown-command' on buffer, sending output to OUTPUT-BUFFER-NAME.
The output buffer name defaults to `markdown-output-buffer-name'.
Expand Down Expand Up @@ -7724,6 +7734,7 @@ Return the name of the output buffer used."
(unless (eq exit-code 0)
(user-error "%s failed with exit code %s"
markdown-command exit-code))))
(markdown--replace-rel2abs output-buffer-name)
output-buffer-name))

(defun markdown-standalone (&optional output-buffer-name)
Expand Down