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

Set font style for GFM-style code blocks in base markdown-mode, too. #2

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 9 additions & 7 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,10 @@ on the value of `markdown-wiki-link-alias-first'.")

(defvar markdown-mode-font-lock-keywords-basic
(list
(cons 'markdown-match-gfm-code-blocks '((1 markdown-pre-face)
(2 markdown-language-keyword-face t t)
(3 markdown-pre-face)
(4 markdown-pre-face)))
(cons 'markdown-match-fenced-code-blocks '((0 markdown-pre-face)))
(cons 'markdown-match-pre-blocks '((0 markdown-pre-face)))
(cons markdown-regex-blockquote 'markdown-blockquote-face)
Expand Down Expand Up @@ -1929,8 +1933,8 @@ because `thing-at-point-looking-at' does not work reliably with
(defun markdown-match-gfm-code-blocks (last)
"Match GFM quoted code blocks from point to LAST."
(let (open lang body close all)
(cond ((and (eq major-mode 'gfm-mode)
(search-forward-regexp "^\\(```\\)\\([^[:space:]]+[[:space:]]*\\)?$" last t))
(cond ((search-forward-regexp
"^\\(```\\)\\([^[:space:]]+[[:space:]]*\\)?$" last t)
(beginning-of-line)
(setq open (list (match-beginning 1) (match-end 1))
lang (list (match-beginning 2) (match-end 2)))
Expand Down Expand Up @@ -2288,7 +2292,9 @@ location determined by `markdown-reference-location'."
(t (read-string "Link URL: "))))
(title (cond
((= (length url) 0) nil)
(switch (substring (match-string 6) 1 -1))
(switch (if (> (length (match-string 6)) 2)
(substring (match-string 6) 1 -1)
nil))
(t (read-string "Link Title (optional): ")))))
(when bounds (delete-region (car bounds) (cdr bounds)))
(markdown-insert-reference-link text label url title)))
Expand Down Expand Up @@ -4856,10 +4862,6 @@ if ARG is omitted or nil."
(append
;; GFM features to match first
(list
(cons 'markdown-match-gfm-code-blocks '((1 markdown-pre-face)
(2 markdown-language-keyword-face t t)
(3 markdown-pre-face)
(4 markdown-pre-face)))
(cons markdown-regex-strike-through '(2 markdown-strike-through-face)))
;; Basic Markdown features (excluding possibly overridden ones)
markdown-mode-font-lock-keywords-basic
Expand Down
13 changes: 12 additions & 1 deletion tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,10 @@ Test point position upon removal and insertion."
"Inline link to reference link conversion."
(markdown-test-string "[text](http://jblevins.org/ \"title\")"
(execute-kbd-macro (read-kbd-macro "M-x markdown-insert-reference-link-dwim RET 1 RET"))
(should (string-equal (buffer-string) "[text][1]\n\n[1]: http://jblevins.org/ \"title\"\n"))))
(should (string-equal (buffer-string) "[text][1]\n\n[1]: http://jblevins.org/ \"title\"\n")))
(markdown-test-string "[text](http://jblevins.org/)"
(execute-kbd-macro (read-kbd-macro "M-x markdown-insert-reference-link-dwim RET 1 RET"))
(should (string-equal (buffer-string) "[text][1]\n\n[1]: http://jblevins.org/\n"))))

(ert-deftest test-markdown-insertion/inline-link ()
"Basic tests for `markdown-insert-link'."
Expand Down Expand Up @@ -1791,6 +1794,14 @@ body"
(markdown-test-range-has-face 1 9 nil)
(markdown-test-range-has-face 10 11 markdown-line-break-face)))

(ert-deftest test-markdown-font-lock/gfm-code-block-font-lock ()
"GFM code block font lock test. Now in base markdown-mode as well!"
(markdown-test-file "gfm.text"
(markdown-test-range-has-face 2639 2641 markdown-pre-face) ; ```
(markdown-test-range-has-face 2642 2645 markdown-language-keyword-face) ; lang
(markdown-test-range-has-face 2647 2728 markdown-pre-face) ; code
(markdown-test-range-has-face 2730 2732 markdown-pre-face))) ; ```

;;; Markdown Parsing Functions:

(ert-deftest test-markdown-parsing/reference-definition-basic ()
Expand Down