Sublime Forum

Clojure Code Block in Markdown not Rendering Properly in ST3

#1

Using Sublime Text 3.1.1 (Build 3176) … editing a Markdown file… I have a Clojure code block that isn’t properly rendering. An example of this is:

The SQL block has the background, and the code within the block is properly rendered for a SQL file.

But above this, the Clojure block is not properly being rendered. It’s detected as a code block, but the language isn’t identified, and it look like straight text.

Every other language block I’ve tried works just fine - it’s just Clojure.

What am I missing?

0 Likes

#2

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.

  1. Install PackageResourceViewer if you don’t already have it installed
  2. Select PackageResourceViewer: Open Resource from the command palette (make sure you don’t accidentlly pick the Extract command)
  3. Select Markdown and then Markdown.sublime-syntax to open the syntax definition
  4. Navigate to line 923, where it says fenced-code-block:
  5. 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.
  6. 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.

1 Like

#3

I have submitted the issue to the Default Package folks - thanks!

I was unable to installed PackageResourceViewer from Package Control - it wasn’t in the list, but I cloned the repo in the Packages directory, and that worked fine.

The fix was perfect, and that’s exactly what I needed. Thanks!

0 Likes