Skip to content
jgchristopher on GitHub jgchristopher on Mastodon

Adding .mdx support to LazyVim

Prior Work


If you are interested in adding highlight support for .mdx files in LazyVim the following is what I did to accomplish this.

Add the following directories and files to update how the markdown parser works

├── after
│   └── queries
│       └── markdown
│           ├── highlights.scm
│           └── injections.scm

highlights.scm content

; extends
((inline) @_inline (#match? @_inline "^\(import\|export\)")) @nospell

injections.scm content

; extends
((inline) @_inline (#match? @_inline "^\(import\|export\)")) @tsx

Add a lua/plugins/treesitter.lua file and add the following.

return {
    opts = function(_, opts)
      if type(opts.ensure_installed) == "table" then
        vim.list_extend(opts.ensure_installed, { "markdown" })
        vim.treesitter.language.register("markdown", "mdx")

This update ensures that the treesitter ensure_installed table exists and then extends it by adding the markdown parser. It then registers the mdx language to use the markdown parser.

Finally, add the following to lua/config/options.lua

  extension = {
    mdx = "mdx",

This tells Neovim about the mdx file extension.