Skip to content

Commit

Permalink
Make it possible to use style sheet URLs again
Browse files Browse the repository at this point in the history
Only expand `markdown-css-paths` that clearly are relative.

This disables the *unreleased* support for relative paths without a
"./", "../" or "~" prefix.

Add an extra `markdown-css-paths` test that ensures we don't break URL
support going forward.

Fixes #869.
  • Loading branch information
mattiasb committed Jan 8, 2025
1 parent 8692afc commit 3898a12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -7736,7 +7736,9 @@ Standalone XHTML output is identified by an occurrence of

(defun markdown-stylesheet-link-string (stylesheet-path)
(concat "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\""
(expand-file-name stylesheet-path)
(or (and (string-match-p (rx (or "~" "./" "../")) stylesheet-path)
(expand-file-name stylesheet-path))
stylesheet-path)
"\" />"))

(defun markdown-escape-title (title)
Expand Down
15 changes: 14 additions & 1 deletion tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -6182,6 +6182,19 @@ bar baz"
(kill-buffer obuffer)
(delete-file ofile))))

(ert-deftest test-markdown-export/url-css-path ()
"Test `markdown-css-paths' as URL."
(let ((markdown-css-paths '("http://www.example.com/style.css")))
(markdown-test-temp-file "inline.text"
(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=\"http://www.example.com/style.css\"")))
(kill-buffer buffer)
(delete-file file)))))

(ert-deftest test-markdown-export/buffer-local-css-path ()
"Test buffer local `markdown-css-paths'"
(let ((markdown-css-paths '("/global.css")))
Expand All @@ -6198,7 +6211,7 @@ bar baz"

(ert-deftest test-markdown-export/relative-css-path ()
"Test relative `markdown-css-paths'."
(let ((markdown-css-paths '("style.css")))
(let ((markdown-css-paths '("./style.css")))
(markdown-test-temp-file "inline.text"
(let* ((markdown-export-kill-buffer nil)
(file (markdown-export))
Expand Down

0 comments on commit 3898a12

Please sign in to comment.