Skip to content

Commit

Permalink
feat: add support for parsing mentions (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanouil authored Jul 14, 2024
1 parent 0184849 commit 4b9f088
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions _extensions/github/github.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ local function is_empty(s)
return s == nil or s == ''
end

local function github_uri(text, uri)
if not is_empty(uri) and not is_empty(text) then
return pandoc.Link(text, uri)
end
end

local github_repository = nil

function get_repository(meta)
Expand Down Expand Up @@ -75,7 +81,7 @@ function issues(elem)
end
end

return uri, text
return github_uri(text, uri)
end

function commits(elem)
Expand Down Expand Up @@ -117,18 +123,39 @@ function commits(elem)
end
end

return uri, text
return github_uri(text, uri)
end

function github(elem)
uri, text = issues(elem)
if not is_empty(uri) and not is_empty(text) then
return pandoc.Link(text, uri)
function mentions(elem)
local uri = nil
local text = nil
if elem.text:match("^@(%w+)$") then
local mention = elem.text:match("^@(%w+)$")
uri = "https://github.com/" .. mention
text = pandoc.utils.stringify(elem.text)
end

uri, text = commits(elem)
if not is_empty(uri) and not is_empty(text) then
return pandoc.Link(text, uri)
return github_uri(text, uri)
end

function github(elem)
local link = nil
if is_empty(link) then
link = issues(elem)
end

if is_empty(link) then
link = commits(elem)
end

-- if is_empty(link) then
-- link = mentions(elem)
-- end

if is_empty(link) then
return elem
else
return link
end
end

Expand Down

0 comments on commit 4b9f088

Please sign in to comment.