12032024
This commit is contained in:
parent
663f358e99
commit
14cedae718
1 changed files with 26 additions and 20 deletions
|
@ -1,26 +1,32 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.InsertMarkdownURL()
|
function M.InsertMarkdownURL()
|
||||||
local url = vim.fn.getreg "+"
|
local url = vim.fn.getreg("+")
|
||||||
if url == "" then return end
|
if url == "" then
|
||||||
local cmd = "curl -L " .. vim.fn.shellescape(url) .. " 2>/dev/null"
|
return
|
||||||
local handle = io.popen(cmd)
|
end
|
||||||
if not handle then return end
|
local cmd = "curl -L " .. vim.fn.shellescape(url) .. " 2>/dev/null"
|
||||||
local html = handle:read "*a"
|
local handle = io.popen(cmd)
|
||||||
handle:close()
|
if not handle then
|
||||||
local title = ""
|
return
|
||||||
local pattern = "<title>(.-)</title>"
|
end
|
||||||
local m = string.match(html, pattern)
|
local html = handle:read("*a")
|
||||||
if m then title = m end
|
handle:close()
|
||||||
if title ~= "" then
|
local title = ""
|
||||||
title = title:gsub("%[", "(")
|
local pattern = "<title[^>]*>(.-)</title>"
|
||||||
title = title:gsub("%]", ")")
|
local m = string.match(html, pattern)
|
||||||
local markdownLink = "[" .. title .. "](" .. url .. ")"
|
if m then
|
||||||
vim.api.nvim_put({markdownLink}, "", true, true)
|
title = m
|
||||||
-- vim.api.nvim_command("call append(line('.'), '" .. markdownLink .. "')")
|
end
|
||||||
else
|
if title ~= "" then
|
||||||
print("Title not found for link")
|
title = title:gsub("%[", "(")
|
||||||
end
|
title = title:gsub("%]", ")")
|
||||||
|
local markdownLink = "[" .. title .. "](" .. url .. ")"
|
||||||
|
vim.api.nvim_put({ markdownLink }, "", true, true)
|
||||||
|
-- vim.api.nvim_command("call append(line('.'), '" .. markdownLink .. "')")
|
||||||
|
else
|
||||||
|
print("Title not found for link")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Reference in a new issue