A MyST Markdown plugin for neovim with tree-sitter backend support.
This plugin provides syntax highlighting and filetype detection for MyST (Markedly Structured Text) markdown files in Neovim. It extends the standard markdown highlighting with MyST-specific features like directives and roles.
- Automatic filetype detection for MyST markdown files
- Code-cell directive highlighting with language-specific syntax highlighting for
{code-cell}
directives - Tree-sitter integration for robust parsing
- Markdown compatibility - works alongside existing markdown features
Using lazy.nvim
{
'QuantEcon/myst-markdown-tree-sitter.nvim',
dependencies = {'nvim-treesitter/nvim-treesitter'},
ft = {"markdown", "myst"},
config = function()
-- Your MyST setup here
-- Ensure this runs after treesitter is loaded
require('myst-markdown').setup()
end,
priority = 1000, -- Load after other markdown plugins
}
Configuration Options Explained:
ft = {"markdown", "myst"}
- Lazy loads the plugin only when opening markdown or MyST files, improving startup performancepriority = 1000
- Ensures this plugin loads after other markdown plugins to prevent highlighting conflictsconfig
function - Runs the setup after treesitter is properly loaded
Using packer.nvim
use {
'QuantEcon/myst-markdown-tree-sitter.nvim',
requires = {'nvim-treesitter/nvim-treesitter'},
config = function()
require('myst-markdown').setup()
end
}
To test unreleased changes from a specific branch (useful for testing fixes before they're merged):
Using lazy.nvim
{
'QuantEcon/myst-markdown-tree-sitter.nvim',
branch = 'branch-name', -- Replace with the actual branch name
dependencies = {'nvim-treesitter/nvim-treesitter'},
ft = {"markdown", "myst"},
config = function()
-- Your MyST setup here
-- Ensure this runs after treesitter is loaded
require('myst-markdown').setup()
end,
priority = 1000, -- Load after other markdown plugins
}
Note: After changing branches or updating the plugin, you may need to:
- Restart Neovim
- Run
:PackerSync
(for packer) or:Lazy sync
(for lazy.nvim) - Run
:TSUpdate
to ensure tree-sitter parsers are up to date
- Neovim >= 0.8.0
- nvim-treesitter
- Tree-sitter markdown parser (
TSInstall markdown markdown_inline
)
The plugin automatically detects MyST markdown files based on content patterns and applies appropriate syntax highlighting.
For debugging and manual control, the plugin provides these commands:
:MystDebug
- Show debugging information about MyST state and tree-sitter queries:MystStatus
- Quick health check of MyST highlighting status
These commands are useful for debugging highlighting issues and testing MyST functionality.
MyST code-cell directives like this:
```{code-cell} python
import pandas as pd
df = pd.DataFrame()
print(df)
```
Will be highlighted with language-specific syntax highlighting, similar to standard markdown code blocks.
Supported Languages in Code Cells:
- Python (
python
) - JavaScript (
javascript
) - TypeScript (
typescript
) - Bash (
bash
) - R (
r
) - Julia (
julia
) - C (
c
) - C++ (
cpp
) - Rust (
rust
) - Go (
go
)
For other languages, ensure you have the corresponding tree-sitter parser installed with :TSInstall <language>
.
The plugin provides syntax highlighting for MyST {code-cell}
directives with language-specific syntax highlighting support.
The plugin works automatically without configuration:
require('myst-markdown').setup()
The plugin provides several commands for troubleshooting and manual control:
:MystStatus
- Quick health check of MyST highlighting status:MystDebug
- Detailed debugging information with diagnostic suggestions
If MyST highlighting is not working:
- Run
:MystStatus
for a quick health check - For detailed diagnosis, run
:MystDebug
- Ensure the file contains MyST directives like
{code-cell}
- Verify nvim-treesitter is installed and markdown parser is available
A sample MyST file is provided in test/sample.md
for testing the plugin functionality.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.