Skip to content

Commit

Permalink
feat(interlinks): filter on py domain by default (#254)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmbuhr authored Aug 29, 2023
1 parent dc59f28 commit e02bcee
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions _extensions/interlinks/interlinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ end

local inventory = {}

function lookup(search_object)
local function lookup(search_object)

local results = {}
for ii, inventory in ipairs(inventory) do
for jj, item in ipairs(inventory.items) do
for _, inv in ipairs(inventory) do
for _, item in ipairs(inv.items) do
-- e.g. :external+<inv_name>:<domain>:<role>:`<name>`
if item.inv_name and item.inv_name ~= search_object.inv_name then
goto continue
Expand All @@ -31,7 +31,9 @@ function lookup(search_object)
if search_object.domain and item.domain ~= search_object.domain then
goto continue
else
table.insert(results, item)
if search_object.domain or item.domain == "py" then
table.insert(results, item)
end

goto continue
end
Expand All @@ -44,19 +46,17 @@ function lookup(search_object)
return results[1]
end
if #results > 1 then
print("Found multiple matches for " .. search_object.name)
quarto.utils.dump(results)
return nil
quarto.log.warning("Found multiple matches for " .. search_object.name .. ", using the first match.")
return results[1]
end
if #results == 0 then
print("Found no matches for object:")
quarto.utils.dump(search_object)
quarto.log.warning("Found no matches for object:\n", search_object)
end

return nil
end

function mysplit (inputstr, sep)
local function mysplit (inputstr, sep)
if sep == nil then
sep = "%s"
end
Expand Down Expand Up @@ -97,15 +97,15 @@ local function build_search_object(str)
search.role = normalize_role(t[3])
search.name = t[4]:match("%%60(.*)%%60")
else
print("couldn't parse this link: " .. str)
quarto.log.warning("couldn't parse this link: " .. str)
return {}
end
else
search.name = str:match("%%60(.*)%%60")
end

if search.name == nil then
print("couldn't parse this link: " .. str)
quarto.log.warning("couldn't parse this link: " .. str)
return {}
end

Expand All @@ -116,7 +116,7 @@ local function build_search_object(str)
return search
end

function report_broken_link(link, search_object, replacement)
local function report_broken_link(link, search_object, replacement)
-- TODO: how to unescape html elements like [?
return pandoc.Code(pandoc.utils.stringify(link.content))
end
Expand Down Expand Up @@ -154,7 +154,7 @@ function Link(link)
return link
end

function fixup_json(json, prefix)
local function fixup_json(json, prefix)
for _, item in ipairs(json.items) do
item.uri = prefix .. item.uri
end
Expand Down

0 comments on commit e02bcee

Please sign in to comment.