Skip to content

Commit e18cf24

Browse files
committed
feat(org): support bare link syntax
1 parent e624cf0 commit e18cf24

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

lua/image/integrations/org.lua

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local document = require("image/utils/document")
2+
local magic = require("image/utils/magic")
23

34
return document.create_document_integration({
45
name = "org",
@@ -18,9 +19,8 @@ return document.create_document_integration({
1819

1920
local images = {}
2021
local query = vim.treesitter.query.parse('org', [[
21-
(link_desc
22-
url: (expr) @image_link
23-
(#match? @image_link "^(file:)?[^ ]+\\.(png|jpe?g|gif|webp)$"))
22+
(link_desc url: (expr) @image_link)
23+
(link url: (expr) @image_link)
2424
]])
2525

2626
for _, node in query:iter_captures(root, bufnr) do
@@ -30,20 +30,22 @@ return document.create_document_integration({
3030
local srcfile_abspath = vim.api.nvim_buf_get_name(0)
3131
local base_dir = vim.fn.fnamemodify(srcfile_abspath, ":h")
3232
local abspath = vim.fn.fnamemodify(base_dir .. "/" .. relpath, ":p")
33-
local start_row, start_col, end_row, end_col = node:range()
34-
table.insert(
35-
images,
36-
{
37-
node = node,
38-
range = {
39-
start_row = start_row,
40-
start_col = start_col,
41-
end_row = end_row,
42-
end_col = end_col,
43-
},
44-
url = abspath,
45-
}
46-
)
33+
if magic.is_image(abspath) then
34+
local start_row, start_col, end_row, end_col = node:range()
35+
table.insert(
36+
images,
37+
{
38+
node = node,
39+
range = {
40+
start_row = start_row,
41+
start_col = start_col,
42+
end_row = end_row,
43+
end_col = end_col,
44+
},
45+
url = abspath,
46+
}
47+
)
48+
end
4749
end
4850
end
4951

0 commit comments

Comments
 (0)