-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmermaid.lua
More file actions
55 lines (51 loc) · 1.23 KB
/
mermaid.lua
File metadata and controls
55 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local M = {}
local function exec(opt)
if not vim.fn.executable("mmdc") then
vim.notify("Mermaid: 没有 mmdc 命令", vim.log.levels.ERROR)
return
end
local p = vim.fn.expand("%:p:r")
local cmd
if opt.args and #opt.args > 0 then
cmd = vim.deepcopy(opt.args)
else
local args = {
"-i",
opt.file,
"-o",
p .. ".svg",
}
cmd = args
end
table.insert(cmd, 1, "mmdc")
local sid = require("kide").timer_stl_status("")
local result = vim.system(cmd):wait()
require("kide").clean_stl_status(sid, result.code)
if result.code == 0 then
vim.notify("Mermaid: export success", vim.log.levels.INFO)
else
vim.notify("Mermaid: export error", vim.log.levels.ERROR)
end
end
local function init()
local group = vim.api.nvim_create_augroup("mermaid_export", { clear = true })
vim.api.nvim_create_autocmd({ "FileType" }, {
group = group,
pattern = { "mermaid" },
desc = "Export Mermaid file",
callback = function(o)
vim.api.nvim_buf_create_user_command(o.buf, "Mmdc", function(opts)
exec({
args = opts.fargs,
file = o.file,
})
end, {
nargs = "*",
})
end,
})
end
M.setup = function()
init()
end
return M