Skip to content

Commit 4b9f088

Browse files
authored
feat: add support for parsing mentions (#1)
1 parent 0184849 commit 4b9f088

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

_extensions/github/github.lua

+36-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ local function is_empty(s)
2626
return s == nil or s == ''
2727
end
2828

29+
local function github_uri(text, uri)
30+
if not is_empty(uri) and not is_empty(text) then
31+
return pandoc.Link(text, uri)
32+
end
33+
end
34+
2935
local github_repository = nil
3036

3137
function get_repository(meta)
@@ -75,7 +81,7 @@ function issues(elem)
7581
end
7682
end
7783

78-
return uri, text
84+
return github_uri(text, uri)
7985
end
8086

8187
function commits(elem)
@@ -117,18 +123,39 @@ function commits(elem)
117123
end
118124
end
119125

120-
return uri, text
126+
return github_uri(text, uri)
121127
end
122128

123-
function github(elem)
124-
uri, text = issues(elem)
125-
if not is_empty(uri) and not is_empty(text) then
126-
return pandoc.Link(text, uri)
129+
function mentions(elem)
130+
local uri = nil
131+
local text = nil
132+
if elem.text:match("^@(%w+)$") then
133+
local mention = elem.text:match("^@(%w+)$")
134+
uri = "https://github.com/" .. mention
135+
text = pandoc.utils.stringify(elem.text)
127136
end
128137

129-
uri, text = commits(elem)
130-
if not is_empty(uri) and not is_empty(text) then
131-
return pandoc.Link(text, uri)
138+
return github_uri(text, uri)
139+
end
140+
141+
function github(elem)
142+
local link = nil
143+
if is_empty(link) then
144+
link = issues(elem)
145+
end
146+
147+
if is_empty(link) then
148+
link = commits(elem)
149+
end
150+
151+
-- if is_empty(link) then
152+
-- link = mentions(elem)
153+
-- end
154+
155+
if is_empty(link) then
156+
return elem
157+
else
158+
return link
132159
end
133160
end
134161

0 commit comments

Comments
 (0)