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

Commit fdb0ebe

Browse files
feat: open in the browser
included the original link in index.json and add mappings NOTE: docs must be rebuilt in order to use this feature
1 parent ed98d03 commit fdb0ebe

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Here is the default configuration:
7272
cmd_ignore = {}, -- ignore cmd rendering for the listed docs
7373
picker_cmd = false, -- use cmd previewer in picker preview
7474
picker_cmd_args = {}, -- example using glow: { "-p" }
75+
mappings = { -- keymaps for the doc buffer
76+
open_in_browser = ""
77+
}
7578
ensure_installed = {}, -- get automatically installed
7679
after_open = function(bufnr) end, -- callback that runs after the Devdocs window is opened. Devdocs buffer ID will be passed in
7780
}

lua/nvim-devdocs/build.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ local function build_docs(entry, index, docs)
5252

5353
for i, index_entry in ipairs(index.entries) do
5454
local main = vim.split(index_entry.path, "#")[1]
55+
index.entries[i].link = index.entries[i].path
5556
index.entries[i].path = path_map[index_entry.path] or path_map[main]
5657
end
5758

lua/nvim-devdocs/config.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ local config = {
1616
picker_cmd = false,
1717
picker_cmd_args = {},
1818
ensure_installed = {},
19-
after_open = function() end
19+
mappings = {
20+
open_in_browser = "",
21+
},
22+
after_open = function() end,
2023
}
2124

2225
M.get = function() return config end

lua/nvim-devdocs/operations.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ M.get_all_entries = function()
178178
name = string.format("[%s] %s", alias, doc_entry.name),
179179
alias = alias,
180180
path = doc_entry.path,
181+
link = doc_entry.link,
181182
}
182183
table.insert(entries, entry)
183184
end
@@ -186,7 +187,7 @@ M.get_all_entries = function()
186187
return entries
187188
end
188189

189-
M.open = function(alias, bufnr, pattern, float)
190+
M.open = function(entry, bufnr, pattern, float)
190191
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
191192

192193
if not float then
@@ -210,7 +211,7 @@ M.open = function(alias, bufnr, pattern, float)
210211

211212
vim.fn.search(pattern)
212213

213-
local ignore = vim.tbl_contains(plugin_config.cmd_ignore, alias)
214+
local ignore = vim.tbl_contains(plugin_config.cmd_ignore, entry.alias)
214215
if plugin_config.previewer_cmd and not ignore then
215216
vim.bo[bufnr].ft = "glow"
216217

@@ -238,6 +239,18 @@ M.open = function(alias, bufnr, pattern, float)
238239
vim.bo[bufnr].ft = "markdown"
239240
end
240241

242+
local slug = entry.alias:gsub("-", "~")
243+
local keymaps = plugin_config.mappings
244+
local set_buf_keymap = function(key, action, description)
245+
vim.keymap.set("n", key, action, { buffer = bufnr, desc = description })
246+
end
247+
248+
set_buf_keymap(
249+
keymaps.open_in_browser,
250+
function() vim.ui.open("https://devdocs.io/" .. slug .. "/" .. entry.link) end,
251+
"Open in the browser"
252+
)
253+
241254
plugin_config.after_open(bufnr)
242255
end
243256

lua/nvim-devdocs/pickers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ local open_doc = function(float)
104104

105105
local splited_path = vim.split(selection.value.path, ",")
106106

107-
operations.open(selection.value.alias, bufnr, splited_path[2], float)
107+
operations.open(selection.value, bufnr, splited_path[2], float)
108108
end
109109

110110
M.installation_picker = function()

0 commit comments

Comments
 (0)