From 90b964e27ddbfa1c625c48259e2a77d75fb51ca4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Tue, 23 Aug 2016 09:48:37 +0200 Subject: [PATCH] Allow using relative links from the file to preview, references issue #11 Change the implementation of "markdown-preview--open-browser-preview" to copy "preview.html" into the directory of the Markdown file to be previewed and browse-url that file instead. --- markdown-preview-mode.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/markdown-preview-mode.el b/markdown-preview-mode.el index e75afc0..058103a 100644 --- a/markdown-preview-mode.el +++ b/markdown-preview-mode.el @@ -74,7 +74,12 @@ (defun markdown-preview--open-browser-preview () "Open the markdown preview in the browser." - (browse-url markdown-preview--preview-url)) + (let* ((dir-of-buffer-to-preview (file-name-directory + (buffer-file-name (get-buffer (buffer-name))))) + (preview-file (concat dir-of-buffer-to-preview ".markdown-preview.html"))) + (if (not (file-exists-p preview-file)) + (copy-file markdown-preview--preview-url preview-file)) + (browse-url preview-file))) (defun markdown-preview--stop-websocket-server () "Stop the `markdown-preview' websocket server."