Skip to content

Commit

Permalink
Merge pull request #870 from mattiasb/fix/869-http-css
Browse files Browse the repository at this point in the history
Make it possible to use style sheet URLs again
  • Loading branch information
syohex authored Jan 9, 2025
2 parents 8692afc + 5ee6a11 commit e100778
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- 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-855][]
(if the path starts with `./` or `../`) [GH-855][] [GH-870][]

[gh-780]: https://github.com/jrblevin/markdown-mode/issues/780
[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802
Expand All @@ -43,6 +43,7 @@
[gh-845]: https://github.com/jrblevin/markdown-mode/issues/845
[gh-848]: https://github.com/jrblevin/markdown-mode/issues/848
[gh-855]: https://github.com/jrblevin/markdown-mode/issues/855
[gh-870]: https://github.com/jrblevin/markdown-mode/issues/870

# Markdown Mode 2.6

Expand Down
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 e100778

Please sign in to comment.