Skip to content

Commit b3b875b

Browse files
authored
Merge pull request #200 from neo451/dev2
feat: make links correct markdown syntax with [^1] and <auto_link>
2 parents c6c035e + 3df36ce commit b3b875b

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

lua/feed/config.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ formats.date_short = function(id, db)
7171
end
7272

7373
formats.link = function(id, db)
74-
return db[id].link and db[id].link:sub(1, 90) or ""
74+
local utils = require("feed.utils")
75+
local link = db[id].link and db[id].link or ""
76+
link = utils.truncate(link, 90)
77+
return "<" .. link .. ">"
7578
end
7679

7780
formats.feed = function(id, db)

lua/feed/pandoc/gfm.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Writer(doc, opts)
2525
ref_counter = ref_counter + 1
2626
refs[ref_counter] = elem.target
2727
local text = pandoc.utils.stringify(elem.content)
28-
return pandoc.RawInline("markdown", "[" .. text .. "][" .. ref_counter .. "]")
28+
return pandoc.RawInline("markdown", "[" .. text .. "][^" .. ref_counter .. "]")
2929
end,
3030
Image = function(elem)
3131
if elem.src:find("data:image/svg%+xml") then
@@ -53,7 +53,7 @@ function Writer(doc, opts)
5353
if ref_counter > 0 then
5454
table.insert(links_blocks, pandoc.Strong("Links"))
5555
for i = 1, ref_counter do
56-
table.insert(links_blocks, pandoc.Para(pandoc.Str(("[%d] %s"):format(i, refs[i]))))
56+
table.insert(links_blocks, pandoc.Para(pandoc.Str(("[^%d] <%s>"):format(i, refs[i]))))
5757
end
5858
new_doc.blocks = new_doc.blocks .. links_blocks
5959
end

lua/feed/utils/url.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ end
2929

3030
--- Returns all URLs in markdown buffer, if any.
3131
---@param cur_link string
32+
---@param lines? string[]
3233
---@return string[][]
33-
M.get_urls = function(cur_link)
34-
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
34+
M.get_urls = function(cur_link, lines)
35+
lines = lines or vim.api.nvim_buf_get_lines(0, 0, -1, false)
3536
local res = { cur_link }
3637
for _, line in ipairs(lines) do
37-
if line:match("^%[%d+%] %s*") then
38-
local url = line:match("%[%d+%] %s*(%S+)")
38+
if line:match("^%[%^%d+%]%s*") then
39+
local url = line:match("%[%^%d+%] %s*<(%S+)>")
3940
table.insert(res, url)
4041
end
4142
end

0 commit comments

Comments
 (0)