This commit is contained in:
foozzi 2024-03-12 11:44:35 -04:00
parent 663f358e99
commit 14cedae718

View file

@ -1,17 +1,23 @@
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
return
end
local cmd = "curl -L " .. vim.fn.shellescape(url) .. " 2>/dev/null" local cmd = "curl -L " .. vim.fn.shellescape(url) .. " 2>/dev/null"
local handle = io.popen(cmd) local handle = io.popen(cmd)
if not handle then return end if not handle then
local html = handle:read "*a" return
end
local html = handle:read("*a")
handle:close() handle:close()
local title = "" local title = ""
local pattern = "<title>(.-)</title>" local pattern = "<title[^>]*>(.-)</title>"
local m = string.match(html, pattern) local m = string.match(html, pattern)
if m then title = m end if m then
title = m
end
if title ~= "" then if title ~= "" then
title = title:gsub("%[", "(") title = title:gsub("%[", "(")
title = title:gsub("%]", ")") title = title:gsub("%]", ")")