File tree 3 files changed +29
-1
lines changed
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ require('render-markdown').setup({
101
101
})
102
102
```
103
103
104
+ # Commands
105
+
106
+ ` :RenderMarkdownToggle ` - Switch between enabling & disabling this plugin
107
+
108
+ - Function can also be accessed directly through ` require('render-markdown').toggle() `
109
+
104
110
# Purpose
105
111
106
112
There are many existing markdown rendering plugins in the Neovim ecosystem. However,
Original file line number Diff line number Diff line change @@ -75,9 +75,10 @@ function M.setup(opts)
75
75
},
76
76
}
77
77
state .config = vim .tbl_deep_extend (' force' , default_config , opts or {})
78
+ state .enabled = true
78
79
79
80
-- Call immediately to re-render on LazyReload
80
- M .refresh ( )
81
+ vim . schedule ( M .refresh )
81
82
82
83
vim .api .nvim_create_autocmd ({
83
84
' FileChangedShellPost' ,
@@ -91,16 +92,36 @@ function M.setup(opts)
91
92
vim .schedule (M .refresh )
92
93
end ,
93
94
})
95
+
96
+ vim .api .nvim_create_user_command (
97
+ ' RenderMarkdownToggle' ,
98
+ M .toggle ,
99
+ { desc = ' Switch between enabling & disabling render markdown plugin' }
100
+ )
94
101
end
95
102
96
103
M .namespace = vim .api .nvim_create_namespace (' render-markdown.nvim' )
97
104
105
+ M .toggle = function ()
106
+ if state .enabled then
107
+ state .enabled = false
108
+ vim .schedule (M .clear )
109
+ else
110
+ state .enabled = true
111
+ -- Call to refresh must happen after state change
112
+ vim .schedule (M .refresh )
113
+ end
114
+ end
115
+
98
116
M .clear = function ()
99
117
-- Remove existing highlights / virtual text
100
118
vim .api .nvim_buf_clear_namespace (0 , M .namespace , 0 , - 1 )
101
119
end
102
120
103
121
M .refresh = function ()
122
+ if not state .enabled then
123
+ return
124
+ end
104
125
if not vim .tbl_contains (state .config .file_types , vim .bo .filetype ) then
105
126
return
106
127
end
Original file line number Diff line number Diff line change 21
21
--- @field public highlights Highlights
22
22
23
23
--- @class State
24
+ --- @field enabled boolean
24
25
--- @field config Config
25
26
local state = {}
26
27
return state
You can’t perform that action at this time.
0 commit comments