Skip to content

Commit e02bcee

Browse files
authored
feat(interlinks): filter on py domain by default (#254)
* cleanup * fix: filter for "py" domain * also take object if domain is specified explicitly * use proper logging log.warning already uses log.output, which uses log.dump see https://github.com/pandoc-ext/logging
1 parent dc59f28 commit e02bcee

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

_extensions/interlinks/interlinks.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ end
1010

1111
local inventory = {}
1212

13-
function lookup(search_object)
13+
local function lookup(search_object)
1414

1515
local results = {}
16-
for ii, inventory in ipairs(inventory) do
17-
for jj, item in ipairs(inventory.items) do
16+
for _, inv in ipairs(inventory) do
17+
for _, item in ipairs(inv.items) do
1818
-- e.g. :external+<inv_name>:<domain>:<role>:`<name>`
1919
if item.inv_name and item.inv_name ~= search_object.inv_name then
2020
goto continue
@@ -31,7 +31,9 @@ function lookup(search_object)
3131
if search_object.domain and item.domain ~= search_object.domain then
3232
goto continue
3333
else
34-
table.insert(results, item)
34+
if search_object.domain or item.domain == "py" then
35+
table.insert(results, item)
36+
end
3537

3638
goto continue
3739
end
@@ -44,19 +46,17 @@ function lookup(search_object)
4446
return results[1]
4547
end
4648
if #results > 1 then
47-
print("Found multiple matches for " .. search_object.name)
48-
quarto.utils.dump(results)
49-
return nil
49+
quarto.log.warning("Found multiple matches for " .. search_object.name .. ", using the first match.")
50+
return results[1]
5051
end
5152
if #results == 0 then
52-
print("Found no matches for object:")
53-
quarto.utils.dump(search_object)
53+
quarto.log.warning("Found no matches for object:\n", search_object)
5454
end
5555

5656
return nil
5757
end
5858

59-
function mysplit (inputstr, sep)
59+
local function mysplit (inputstr, sep)
6060
if sep == nil then
6161
sep = "%s"
6262
end
@@ -97,15 +97,15 @@ local function build_search_object(str)
9797
search.role = normalize_role(t[3])
9898
search.name = t[4]:match("%%60(.*)%%60")
9999
else
100-
print("couldn't parse this link: " .. str)
100+
quarto.log.warning("couldn't parse this link: " .. str)
101101
return {}
102102
end
103103
else
104104
search.name = str:match("%%60(.*)%%60")
105105
end
106106

107107
if search.name == nil then
108-
print("couldn't parse this link: " .. str)
108+
quarto.log.warning("couldn't parse this link: " .. str)
109109
return {}
110110
end
111111

@@ -116,7 +116,7 @@ local function build_search_object(str)
116116
return search
117117
end
118118

119-
function report_broken_link(link, search_object, replacement)
119+
local function report_broken_link(link, search_object, replacement)
120120
-- TODO: how to unescape html elements like [?
121121
return pandoc.Code(pandoc.utils.stringify(link.content))
122122
end
@@ -154,7 +154,7 @@ function Link(link)
154154
return link
155155
end
156156

157-
function fixup_json(json, prefix)
157+
local function fixup_json(json, prefix)
158158
for _, item in ipairs(json.items) do
159159
item.uri = prefix .. item.uri
160160
end

0 commit comments

Comments
 (0)