From caff78e874eb12b198c7fcc172c464b3b5095d24 Mon Sep 17 00:00:00 2001 From: Mattias Bengtsson Date: Sat, 16 Nov 2024 18:13:15 +0100 Subject: [PATCH 1/2] Support relative paths in stylesheets --- CHANGES.md | 2 ++ markdown-mode.el | 4 +--- tests/markdown-test.el | 20 +++++++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ca732df0..dddacc1d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,8 @@ - Copy `markdown-css-paths` in the output buffer [GH-834][] - Change temporary buffer name according to the Emacs naming convention [GH-848][] - Mark `markdown-css-paths` safe as file local variables [GH-834][] + - Resolve style sheets in `markdown-css-paths` relative to the Markdown file + [GH-834][] [gh-780]: https://github.com/jrblevin/markdown-mode/issues/780 [gh-802]: https://github.com/jrblevin/markdown-mode/issues/802 diff --git a/markdown-mode.el b/markdown-mode.el index 2152cd60..414d5052 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -7736,9 +7736,7 @@ Standalone XHTML output is identified by an occurrence of (defun markdown-stylesheet-link-string (stylesheet-path) (concat "")) (defun markdown-escape-title (title) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index f6be7d30..6fa5bf77 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -6184,15 +6184,29 @@ bar baz" (ert-deftest test-markdown-export/buffer-local-css-path () "Test buffer local `markdown-css-paths'" - (let ((markdown-css-paths '("./global.css"))) + (let ((markdown-css-paths '("/global.css"))) (markdown-test-temp-file "inline.text" - (setq-local markdown-css-paths '("./local.css")) + (setq-local markdown-css-paths '("/local.css")) (let* ((markdown-export-kill-buffer nil) (file (markdown-export)) (buffer (get-file-buffer file))) (with-current-buffer buffer (goto-char (point-min)) - (should (search-forward "href=\"./local.css\""))) + (should (search-forward "href=\"/local.css\""))) + (kill-buffer buffer) + (delete-file file))))) + +(ert-deftest test-markdown-export/relative-css-path () + "Test relative `markdown-css-paths'." + (let ((markdown-css-paths '("style.css"))) + (markdown-test-temp-file "inline.text" + (let* ((markdown-export-kill-buffer nil) + (file (markdown-export)) + (buffer (get-file-buffer file)) + (expanded-path (file-name-concat default-directory "style.css"))) + (with-current-buffer buffer + (goto-char (point-min)) + (should (search-forward (format "href=\"%s\"" expanded-path)))) (kill-buffer buffer) (delete-file file))))) From 4720aa74ab43e29b09be6718157e42b8f2026bb0 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Sun, 17 Nov 2024 12:25:26 +0900 Subject: [PATCH 2/2] fix for older emacs --- tests/markdown-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 6fa5bf77..9505e4a5 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -6203,7 +6203,7 @@ bar baz" (let* ((markdown-export-kill-buffer nil) (file (markdown-export)) (buffer (get-file-buffer file)) - (expanded-path (file-name-concat default-directory "style.css"))) + (expanded-path (concat default-directory "style.css"))) (with-current-buffer buffer (goto-char (point-min)) (should (search-forward (format "href=\"%s\"" expanded-path))))