Skip to content

Commit

Permalink
Merge pull request #835 from jrblevin/issue-834
Browse files Browse the repository at this point in the history
Copy markdown-css-paths in the output buffer
  • Loading branch information
syohex authored Jun 26, 2024
2 parents 0cdebc8 + 55c8b23 commit 8aab017
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* Improvements:
- Apply url-unescape against URL in an inline link [GH-805][]
- Show mode toggle message only if it is called interactively
- Copy `markdown-css-paths` in the output buffer [GH-834][]

[gh-780]: https://github.com/jrblevin/markdown-mode/issues/780
[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802
[gh-804]: https://github.com/jrblevin/markdown-mode/issues/804
[gh-805]: https://github.com/jrblevin/markdown-mode/issues/805
[gh-817]: https://github.com/jrblevin/markdown-mode/issues/817
[gh-827]: https://github.com/jrblevin/markdown-mode/issues/827
[gh-834]: https://github.com/jrblevin/markdown-mode/issues/834

# Markdown Mode 2.6

Expand Down
78 changes: 32 additions & 46 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -684,52 +684,36 @@ This may also be a cons cell where the behavior for `C-a' and
`C-e' is set separately."
:group 'markdown
:type '(choice
(const :tag "off" nil)
(const :tag "on: after hashes/bullet and before closing tags first" t)
(const :tag "reversed: true line boundary first" reversed)
(cons :tag "Set C-a and C-e separately"
(choice :tag "Special C-a"
(const :tag "off" nil)
(const :tag "on: after hashes/bullet first" t)
(const :tag "reversed: before hashes/bullet first" reversed))
(choice :tag "Special C-e"
(const :tag "off" nil)
(const :tag "on: before closing tags first" t)
(const :tag "reversed: after closing tags first" reversed))))
(const :tag "off" nil)
(const :tag "on: after hashes/bullet and before closing tags first" t)
(const :tag "reversed: true line boundary first" reversed)
(cons :tag "Set C-a and C-e separately"
(choice :tag "Special C-a"
(const :tag "off" nil)
(const :tag "on: after hashes/bullet first" t)
(const :tag "reversed: before hashes/bullet first" reversed))
(choice :tag "Special C-e"
(const :tag "off" nil)
(const :tag "on: before closing tags first" t)
(const :tag "reversed: after closing tags first" reversed))))
:package-version '(markdown-mode . "2.7"))

;;; Markdown-Specific `rx' Macro ==============================================

;; Based on python-rx from python.el.
(eval-and-compile
(defconst markdown-rx-constituents
`((newline . ,(rx "\n"))
;; Note: #405 not consider markdown-list-indent-width however this is never used
(indent . ,(rx (or (repeat 4 " ") "\t")))
(block-end . ,(rx (and (or (one-or-more (zero-or-more blank) "\n") line-end))))
(numeral . ,(rx (and (one-or-more (any "0-9#")) ".")))
(bullet . ,(rx (any "*+:-")))
(list-marker . ,(rx (or (and (one-or-more (any "0-9#")) ".")
(any "*+:-"))))
(checkbox . ,(rx "[" (any " xX") "]")))
"Markdown-specific sexps for `markdown-rx'")

(defun markdown-rx-to-string (form &optional no-group)
"Markdown mode specialized `rx-to-string' function.
This variant supports named Markdown expressions in FORM.
NO-GROUP non-nil means don't put shy groups around the result."
(let ((rx-constituents (append markdown-rx-constituents rx-constituents)))
(rx-to-string form no-group)))

(defmacro markdown-rx (&rest regexps)
"Markdown mode specialized rx macro.
(defmacro markdown-rx (&rest regexps)
"Markdown mode specialized rx macro.
This variant of `rx' supports common Markdown named REGEXPS."
(cond ((null regexps)
(error "No regexp"))
((cdr regexps)
(markdown-rx-to-string `(and ,@regexps) t))
(t
(markdown-rx-to-string (car regexps) t)))))
`(rx-let ((newline "\n")
;; Note: #405 not consider markdown-list-indent-width however this is never used
(indent (or (repeat 4 " ") "\t"))
(block-end (and (or (one-or-more (zero-or-more blank) "\n") line-end)))
(numeral (and (one-or-more (any "0-9#")) "."))
(bullet (any "*+:-"))
(list-marker (or (and (one-or-more (any "0-9#")) ".")
(any "*+:-")))
(checkbox (seq "[" (any " xX") "]")))
(rx ,@regexps)))


;;; Regular Expressions =======================================================
Expand Down Expand Up @@ -7692,12 +7676,14 @@ Return the name of the output buffer used."
Insert the output in the buffer named OUTPUT-BUFFER-NAME."
(interactive)
(setq output-buffer-name (markdown output-buffer-name))
(with-current-buffer output-buffer-name
(set-buffer output-buffer-name)
(unless (markdown-output-standalone-p)
(markdown-add-xhtml-header-and-footer output-buffer-name))
(goto-char (point-min))
(html-mode))
(let ((css-path markdown-css-paths))
(with-current-buffer output-buffer-name
(set-buffer output-buffer-name)
(setq-local markdown-css-paths css-path)
(unless (markdown-output-standalone-p)
(markdown-add-xhtml-header-and-footer output-buffer-name))
(goto-char (point-min))
(html-mode)))
output-buffer-name)

(defun markdown-other-window (&optional output-buffer-name)
Expand Down
14 changes: 14 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -6158,6 +6158,20 @@ bar baz"
(kill-buffer obuffer)
(delete-file ofile))))

(ert-deftest test-markdown-export/buffer-local-css-path ()
"Test buffer local `markdown-css-paths'"
(let ((markdown-css-paths '("./global.css")))
(markdown-test-temp-file "inline.text"
(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\"")))
(kill-buffer buffer)
(delete-file file)))))

;;; Hook tests:

(ert-deftest test-markdown-hook/before-export ()
Expand Down

0 comments on commit 8aab017

Please sign in to comment.