Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 5b6ba3c

Browse files
feat: preview docs with cmd
1 parent 686f991 commit 5b6ba3c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Here is the default configuration:
6767
width = 100,
6868
border = "rounded",
6969
},
70+
previewer_cmd = nil, -- like glow
71+
cmd_args = {}, -- example using glow { "-s", "dark", "-w", "80" }
7072
wrap = false, -- text wrap, only applies to floating window
7173
ensure_installed = {}, -- get automatically installed
7274
}

lua/nvim-devdocs/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ local config = {
1414
width = 100,
1515
border = "rounded",
1616
},
17+
previewer_cmd = nil,
18+
cmd_args = {},
1719
wrap = false,
1820
ensure_installed = {},
1921
}

lua/nvim-devdocs/operations.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local M = {}
22

3+
local job = require("plenary.job")
34
local curl = require("plenary.curl")
45
local path = require("plenary.path")
56

@@ -208,7 +209,6 @@ M.open = function(entry, float)
208209
local lines = vim.split(markdown, "\n")
209210
local buf = vim.api.nvim_create_buf(not float, true)
210211

211-
vim.bo[buf].ft = "markdown"
212212
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
213213
vim.api.nvim_buf_set_option(buf, "modifiable", false)
214214

@@ -230,6 +230,27 @@ M.open = function(entry, float)
230230
vim.wo[win].nu = false
231231
vim.wo[win].relativenumber = false
232232
end
233+
234+
if plugin_config.previewer_cmd then
235+
local chan = vim.api.nvim_open_term(buf, {})
236+
local echo = job:new({ command = "echo", args = { markdown } })
237+
238+
local previewer = job:new({
239+
command = plugin_config.previewer_cmd,
240+
args = plugin_config.cmd_args,
241+
on_stdout = vim.schedule_wrap(function(_, data)
242+
local output_lines = vim.split(data, "\n", {})
243+
for _, line in ipairs(output_lines) do
244+
vim.api.nvim_chan_send(chan, line .. "\r\n")
245+
end
246+
end),
247+
writer = echo,
248+
})
249+
250+
previewer:start()
251+
else
252+
vim.bo[buf].ft = "markdown"
253+
end
233254
end
234255

235256
return M

0 commit comments

Comments
 (0)