preview images of markdown links

This commit is contained in:
Rene Schallner
2021-11-30 15:53:23 +01:00
parent 9dc8e2d95c
commit e52c336391
4 changed files with 52 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
- [ ] yt video
## Dones
- [x] preview images
- [x] insert link to image, with preview
- [x] sorting file picker: devicons, ...
- [x] dailies and weeklies: don't display whole paths: fix entries: display values

View File

@@ -14,7 +14,8 @@ A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](htt
- calendar support
- paste images from clipboard
- toggle [ ] todo status of line
- insert links to images, with **image previews**, via extension _(Linux only)_
- insert links to images
- **image previews**, via extension _(Linux only)_
##### New features are being announced in the [discussions](https://github.com/renerocksai/telekasten.nvim/discussions)!
@@ -302,6 +303,8 @@ The plugin defines the following functions.
- if the `telescope-media-files.nvim` plugin is installed, **a preview of images / media files will be given** during the search.
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is useful for being able to continue to type after link insertion. See also: [Bind it](#4-bind-it).
- example: `insert_link({ i=true })`
- `preview_img()` : uses the `telescope-media-files.nvim` extension to preview the image / media file under the cursor of a markdown image link: `![](path/to/img.png)`. The cursor must be between `(the two parenthesis)`.
- **note**: this requires the `telescope-media-files.nvim` plugin to be installed.
- `setup(opts)`: used for configuring paths, file extension, etc.
To use one of the functions above, just run them with the `:lua ...` command.
@@ -419,6 +422,7 @@ nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
" we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -454,6 +454,15 @@ telekasten.insert_img_link({opts})~
Default: `nil`
*telekasten.preview_img()*
telekasten.preview_img()~
Uses the `telescope-media-files.nvim` extension to preview the image / media
file under the cursor of a markdown image link: `![](path/to/img.png)`. The
cursor must be between `(the two parenthesis)`.
Note:~
This requires the `telescope-media-files.nvim` plugin to be installed.
--------------------------------------------------------------------------------
Section 3.1: Templates *telekasten.templates*
@@ -584,6 +593,7 @@ However, here are some suggestions:
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
" we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -471,6 +471,40 @@ local function FollowLink(opts)
})
end
--
-- PreviewImg:
-- -----------
--
-- preview media
--
local function PreviewImg(_)
vim.cmd("normal yi)")
local fname = vim.fn.getreg('"0')
-- check if fname exists anywhere
local fexists = file_exists(M.Cfg.home .. "/" .. fname)
if fexists == true then
find_files_sorted({
prompt_title = "Preview image/media",
cwd = M.Cfg.home,
default_text = fname,
find_command = M.Cfg.find_command,
filter_extensions = { ".png", ".jpg", ".bmp", ".gif", ".pdf", ".mp4", ".webm" },
preview_type = "media",
attach_mappings = function(prompt_bufnr, _)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
end)
return true
end,
})
else
print("File not found: " .. M.Cfg.home .. "/" .. fname)
end
end
--
-- FindFriends:
-- -----------
@@ -557,7 +591,7 @@ end
-- InsertImgLink:
-- --------------
--
-- Select from notes
-- Insert link to image / media, with optional preview
--
local function InsertImgLink(opts)
opts = opts or {}
@@ -915,5 +949,6 @@ M.toggle_todo = ToggleTodo
M.show_backlinks = ShowBacklinks
M.find_friends = FindFriends
M.insert_img_link = InsertImgLink
M.preview_img = PreviewImg
return M