The markdown syntax that ships with Sublime has rules to detect a fair number of languages in code blocks, but Clojure is not one of them. I don’t know why that’s the case though; it may be deliberate for some reason or just an accidental omission, for example. It may be worth logging an issue on the Default Packages Issue Tracker to let the contributors know.
In the interim, you can use the following steps to add support for this yourself.
- Install PackageResourceViewer if you don’t already have it installed
- Select
PackageResourceViewer: Open Resource
from the command palette (make sure you don’t accidentlly pick the Extract
command)
- Select
Markdown
and then Markdown.sublime-syntax
to open the syntax definition
- Navigate to line 923, where it says
fenced-code-block:
- Add the below lines directly under that line to add a new rule for matching Clojure code blocks. As you see when you look at the file, the code below is mostly identical to the other similar rules for other languages; your addition should have the same indent and look like a seamless addition.
- Save the file
- match: |-
(?x)
{{fenced_code_block_start}}
((?i:clojure|clj))
\s*$\n? # any whitespace until EOL
captures:
0: meta.code-fence.definition.begin.clojure.markdown-gfm
2: punctuation.definition.raw.code-fence.begin.markdown
3: constant.other.language-name.markdown
embed: scope:source.clojure
embed_scope: markup.raw.code-fence.clojure.markdown-gfm
escape: '{{code_fence_escape}}'
escape_captures:
0: meta.code-fence.definition.end.clojure.markdown-gfm
1: punctuation.definition.raw.code-fence.end.markdown
Once you save the file, Sublime will rebuild the Syntax cache (which may take a second or two) and the new rules will immediately jump into effect on any current or newly opened files:
Following these steps will create an override on the Markdown.sublime-syntax
file, which makes Sublime use your copy of the file in favour of the one it ships with. It will keep doing that even if/when the file that it ships with is updated (perhaps to support this very feature itself) without warning you that it’s happening.
My OverrideAudit package will warn you if the underlying file changes on a Sublime Text upgrade, so that you know that this is happening and can verify if you still need the changes.