Skip to content

Commit

Permalink
Support relative paths in stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasb committed Nov 17, 2024
1 parent 1716694 commit 28dad26
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-855][]

[gh-780]: https://github.com/jrblevin/markdown-mode/issues/780
[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802
Expand All @@ -40,6 +42,7 @@
[gh-838]: https://github.com/jrblevin/markdown-mode/issues/838
[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

# Markdown Mode 2.6

Expand Down
4 changes: 1 addition & 3 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -7736,9 +7736,7 @@ 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=\""
(or (and (string-prefix-p "~" stylesheet-path)
(expand-file-name stylesheet-path))
stylesheet-path)
(expand-file-name stylesheet-path)
"\" />"))

(defun markdown-escape-title (title)
Expand Down
20 changes: 17 additions & 3 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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)))))

Expand Down

0 comments on commit 28dad26

Please sign in to comment.