Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative paths in stylesheets #857

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading