Highlighting code blocks in markdown

Figured this out. This was not related to neovim itself, but rather coming from nvim-treesitter plugin.

Comments to this reddit post helped me realize this is enabled by tree-sitter, which made me review my nvim configs and remember that I maintain a list of languages for tree-sitter must recognize.

Here’s the nvim-treesitter config I needed to edit (I use lazy.nvim to maintain neovim plugins):

local M = {
  "nvim-treesitter/nvim-treesitter",
  build = ":TSUpdate",
  config = function()
    require("nvim-treesitter.configs").setup({
      ensure_installed = {
        "bash",
        "fish",
        -- ...
        "nix" -- <- added this line
      },
      highlight = {
        enable = true
      }
    })
  end
}

return { M }

Here’s the end result:

I find this somewhat interesting since code in regular .nix files was highlighted just fine, but code in .md blocks written in nix wasn’t. Aren’t both use the same underlying highlighting mechanism these days?

1 Like