aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md29
-rw-r--r--doc/muwiki.txt43
2 files changed, 50 insertions, 22 deletions
diff --git a/README.md b/README.md
index 7f5abd6..6ec02b3 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ See `:help muwiki` for complete documentation and configuration options.
```lua
vim.pack.add({
- { src = "https://git.3kgcat.fi/muwiki.nvim" }
+ { src = "https://git.3kgcat.fi/muwiki.nvim", name = "muwiki" }
})
```
@@ -108,21 +108,13 @@ vim.api.nvim_create_autocmd("BufWritePre", {
See `:help muwiki-autocmd` for more examples.
-## Configuration Options
-
-### text_extensions
-
-Controls which file extensions open directly in Neovim when using `file://` links. Files with matching extensions bypass `xdg-open` and open in a Neovim buffer instead.
-
-**Default:** `{}` (empty - all file:// links open with xdg-open)
-
-**Format:** Accepts extensions with or without leading dot (e.g., `'txt'` or `'.txt'`)
+## Configuration
**Example:**
```lua
muwiki.setup({
dirs = {{ name = 'default', path = '~/wiki' }},
- -- Open these file types directly in Neovim
+ -- Open matching file:// links in Neovim instead of xdg-open
text_extensions = { 'txt', 'md', 'png' },
})
```
@@ -131,17 +123,12 @@ This allows you to open binary files like PNG images directly in Neovim for hex
**Behavior:**
-**xdg-open:**
-
-- `[Link](https://example.com)`
-- `[Link](file:///path/to/file.mp4)`
-
-**Neovim:**
+- `[Link](https://example.com)` → xdg-open (web)
+- `[Link](file:///path/to/file.mp4)` → xdg-open (file)
+- `[Link](file://../relative/path/to/image.png)` → neovim (file with text_extensions match)
+- `[Link](SomePage.md)` → neovim (wiki)
-- `[Link](file://../relative/path/to/image.png)` → matches text_extensions
-- `[Link](/absolute/path/to/file.txt)`
-- `[Link](../relative/path/to/file.txt)`
-- `[Link](SomePage.md)`
+See `:help muwiki-configuration` for all options.
## Available Actions
diff --git a/doc/muwiki.txt b/doc/muwiki.txt
index c22acb1..92750ae 100644
--- a/doc/muwiki.txt
+++ b/doc/muwiki.txt
@@ -38,7 +38,7 @@ It provides:
Using vim.pack (Neovim 0.12+)~
>
vim.pack.add({
- { src = "https://git.3kgcat.fi/muwiki.nvim" }
+ { src = "https://git.3kgcat.fi/muwiki.nvim", name = "muwiki" }
})
<
@@ -229,6 +229,47 @@ Open with menu example~ *muwiki-au
})
<
+Custom open handler using get_link()~ *muwiki-autocmd-custom-open*
+>
+ vim.api.nvim_create_autocmd("FileType", {
+ pattern = "markdown",
+ callback = function(args)
+ if not muwiki.wiki_root(args.buf) then return end
+ vim.keymap.set('n', '<CR>', function()
+ local link = muwiki.get_link()
+ if not link then
+ vim.notify('No link under cursor', vim.log.levels.WARN)
+ return
+ end
+
+ -- Custom logic based on link type
+ if link.type == 'web' then
+ vim.system({ 'xdg-open', link.target }, { detach = true })
+ elseif link.type == 'file' then
+ local ext = link.target:match('%.([^%.]+)$')
+ if ext == 'png' or ext == 'jpg' or ext == 'jpeg' or ext == 'gif' or ext == 'webp' then
+ vim.system({ 'swayimg', link.target }, { detach = true })
+ elseif ext == 'mp4' or ext == 'mkv' or ext == 'avi' or ext == 'mov' or ext == 'webm' then
+ vim.system({ 'mpv', link.target }, { detach = true })
+ elseif ext == 'pdf' then
+ vim.system({ 'zathura', link.target }, { detach = true })
+ else
+ -- Open in Neovim for other file types
+ local utils = require('muwiki.utils')
+ local file_path = utils.resolve(link.target, nil)
+ vim.cmd('edit ' .. vim.fn.fnameescape(file_path))
+ end
+ else
+ -- Wiki link: open in Neovim
+ local utils = require('muwiki.utils')
+ local file_path = utils.resolve(link.target, nil)
+ vim.cmd('edit ' .. vim.fn.fnameescape(file_path))
+ end
+ end, { buffer = args.buf, desc = "Open link (custom handler)" })
+ end,
+ })
+<
+
==============================================================================
8. HEALTH CHECK *muwiki-health*