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

Add a variable to fontify code block with a default mode #303

Merged
merged 1 commit into from
Jan 1, 2018
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
- Add custom variables `markdown-xhtml-body-preamble` and
`markdown-xhtml-body-epilogue` for wrapping additional XHTML
tags around the output. ([GH-280][], [GH-281][])
- Add custom variable `markdown-fontify-code-block-default` to
fontify code block with a default mode

* Improvements:

Expand Down
11 changes: 9 additions & 2 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8459,6 +8459,11 @@ LANG is a string, and the returned major mode is a symbol."
(intern (concat lang "-mode"))
(intern (concat (downcase lang) "-mode")))))

(defvar markdown-fontify-code-block-default nil
"Default mode to use to fontify code blocks.
This mode is used when automatic detection fails, such as for GFM
code blocks with no language specified.")

(defun markdown-fontify-code-blocks-generic (matcher last)
"Add text properties to next code block from point to LAST.
Use matching function MATCHER."
Expand All @@ -8474,7 +8479,8 @@ Use matching function MATCHER."
(if (bolp) (point-at-bol 2) (point-at-bol 3))))
lang)
(if (and markdown-fontify-code-blocks-natively
(setq lang (markdown-code-block-lang)))
(or (setq lang (markdown-code-block-lang))
markdown-fontify-code-block-default))
(markdown-fontify-code-block-natively lang start end)
(add-text-properties start end '(face markdown-pre-face)))
;; Set background for block as well as opening and closing lines.
Expand All @@ -8500,7 +8506,8 @@ This function is called by Emacs for automatic fontification when
`markdown-fontify-code-blocks-natively' is non-nil. LANG is the
language used in the block. START and END specify the block
position."
(let ((lang-mode (markdown-get-lang-mode lang)))
(let ((lang-mode (if lang (markdown-get-lang-mode lang)
markdown-fontify-code-block-default)))
(when (fboundp lang-mode)
(let ((string (buffer-substring-no-properties start end))
(modified (buffer-modified-p))
Expand Down