Adding .mdx support to LazyVim
Prior Work
- Setting up Neovim for Astro development
- Good enough syntax highlight for MDX in Neovim using Treesitter | Phelipe Teles
- My LazyVim Config
Setup
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
lazyvim/
├── 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 {
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
if type(opts.ensure_installed) == "table" then
vim.list_extend(opts.ensure_installed, { "markdown" })
vim.treesitter.language.register("markdown", "mdx")
end
end,
},
}
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
vim.filetype.add({
extension = {
mdx = "mdx",
},
})
This tells Neovim about the mdx
file extension.