Skip to content
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
8 changes: 8 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4376,6 +4376,14 @@ be used to populate the title attribute when converted to XHTML."
(immediately (markdown-end-of-text-block))
(subtree (markdown-end-of-subtree))
(header (markdown-end-of-defun)))
;; Skip backwards over local variables. This logic is similar to the one
;; used in ‘hack-local-variables’.
(when (and enable-local-variables (eobp))
(search-backward "\n\f" (max (- (point) 3000) (point-min)) :move)
(when (let ((case-fold-search t))
(search-forward "Local Variables:" nil :move))
(beginning-of-line 0)
(when (eq (char-before) ?\n) (backward-char))))
(unless (or (markdown-cur-line-blank-p)
(thing-at-point-looking-at markdown-regex-reference-definition))
(insert "\n"))
Expand Down
20 changes: 20 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,26 @@ Test point position upon removal and insertion."
(should (= (point) 38))
(should (looking-back "https://www.gnu.org/\n\\[2\\]: " nil)))))

(ert-deftest test-markdown-insertion/reference-link-before-file-locals ()
"Test inserting a reference link before file-local variables."
(markdown-test-string "

<!-- Local Variables: -->
<!-- mode: markdown -->
<!-- End: -->
"
(markdown-insert-reference-link "link" "" "http://jblevins.org/")
(should (equal (buffer-substring-no-properties 1 (point-max))
"[link][]

\[link]: http://jblevins.org/

<!-- Local Variables: -->
<!-- mode: markdown -->
<!-- End: -->
"))
(should (equal (point) 9))))

(ert-deftest test-markdown-insertion/inline-to-reference-link ()
"Inline link to reference link conversion with tab completion."
(markdown-test-string "[text](http://jblevins.org/ \"title\")"
Expand Down