Skip to content

Commit c8f333e

Browse files
authored
Merge branch 'main' into interlinks
2 parents f68fa4a + dcdeb41 commit c8f333e

29 files changed

+658
-104
lines changed

.devcontainer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"build": { "dockerfile": "Dockerfile" },
3+
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"quarto.quarto",
8+
"ms-python.python"
9+
]
10+
}
11+
},
12+
13+
"forwardPorts": [8888]
14+
}

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
exclude = docs, test_*, .flake8
2+
exclude = docs, test_*, .flake8, examples
33
max-line-length = 90
44
ignore =
55
# line too long

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM ghcr.io/quarto-dev/quarto:1.4.330
2+
3+
RUN apt-get update && apt-get install -y python3 python3-pip git
4+
RUN pip3 install --upgrade pip
5+
RUN pip3 install --upgrade setuptools jupyterlab ipython jupyterlab-quarto
6+
COPY ./ /quartodoc
7+
WORKDIR /quartodoc
8+
RUN pip3 install -e ".[dev]"

_extensions/interlinks/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: Interlinks
22
author: Michael Chow
3-
version: 1.0.0
3+
version: 1.1.0
44
quarto-required: ">=1.2.0"
55
contributes:
66
filters:

_extensions/interlinks/interlinks.lua

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,86 @@
1+
local function read_inv_text(filename)
2+
-- read file
3+
local file = io.open(filename, "r")
4+
if file == nil then
5+
return nil
6+
end
7+
local str = file:read("a")
8+
file:close()
9+
10+
11+
local project = str:match("# Project: (%S+)")
12+
local version = str:match("# Version: (%S+)")
13+
14+
local data = {project = project, version = version, items = {}}
15+
16+
local ptn_data =
17+
"^" ..
18+
"(.-)%s+" .. -- name
19+
"([%S:]-):" .. -- domain
20+
"([%S]+)%s+" .. -- role
21+
"(%-?%d+)%s+" .. -- priority
22+
"(%S*)%s+" .. -- uri
23+
"(.-)\r?$" -- dispname
24+
25+
26+
-- Iterate through each line in the file content
27+
for line in str:gmatch("[^\r\n]+") do
28+
if not line:match("^#") then
29+
-- Match each line against the pattern
30+
local name, domain, role, priority, uri, dispName = line:match(ptn_data)
31+
32+
-- if name is nil, raise an error
33+
if name == nil then
34+
error("Error parsing line: " .. line)
35+
end
36+
37+
data.items[#data.items + 1] = {
38+
name = name,
39+
domain = domain,
40+
role = role,
41+
priority = priority,
42+
uri = uri,
43+
dispName = dispName
44+
}
45+
end
46+
end
47+
return data
48+
end
49+
150
local function read_json(filename)
51+
252
local file = io.open(filename, "r")
353
if file == nil then
454
return nil
555
end
656
local str = file:read("a")
757
file:close()
8-
return quarto.json.decode(str)
58+
59+
local decoded = quarto.json.decode(str)
60+
return decoded
61+
end
62+
63+
local function read_inv_text_or_json(base_name)
64+
local file = io.open(base_name .. ".txt", "r")
65+
if file then
66+
-- TODO: refactors so we don't just close the file immediately
67+
io.close(file)
68+
json = read_inv_text(base_name .. ".txt")
69+
70+
else
71+
json = read_json(base_name .. ".json")
72+
end
73+
74+
return json
975
end
1076

1177
local inventory = {}
1278

13-
function lookup(search_object)
79+
local function lookup(search_object)
1480

1581
local results = {}
16-
for ii, inventory in ipairs(inventory) do
17-
for jj, item in ipairs(inventory.items) do
82+
for _, inv in ipairs(inventory) do
83+
for _, item in ipairs(inv.items) do
1884
-- e.g. :external+<inv_name>:<domain>:<role>:`<name>`
1985
if item.inv_name and item.inv_name ~= search_object.inv_name then
2086
goto continue
@@ -31,7 +97,9 @@ function lookup(search_object)
3197
if search_object.domain and item.domain ~= search_object.domain then
3298
goto continue
3399
else
34-
table.insert(results, item)
100+
if search_object.domain or item.domain == "py" then
101+
table.insert(results, item)
102+
end
35103

36104
goto continue
37105
end
@@ -44,19 +112,17 @@ function lookup(search_object)
44112
return results[1]
45113
end
46114
if #results > 1 then
47-
print("Found multiple matches for " .. search_object.name)
48-
quarto.utils.dump(results)
49-
return nil
115+
quarto.log.warning("Found multiple matches for " .. search_object.name .. ", using the first match.")
116+
return results[1]
50117
end
51118
if #results == 0 then
52-
print("Found no matches for object:")
53-
quarto.utils.dump(search_object)
119+
quarto.log.warning("Found no matches for object:\n", search_object)
54120
end
55121

56122
return nil
57123
end
58124

59-
function mysplit (inputstr, sep)
125+
local function mysplit (inputstr, sep)
60126
if sep == nil then
61127
sep = "%s"
62128
end
@@ -97,15 +163,15 @@ local function build_search_object(str)
97163
search.role = normalize_role(t[3])
98164
search.name = t[4]:match("%%60(.*)%%60")
99165
else
100-
print("couldn't parse this link: " .. str)
166+
quarto.log.warning("couldn't parse this link: " .. str)
101167
return {}
102168
end
103169
else
104170
search.name = str:match("%%60(.*)%%60")
105171
end
106172

107173
if search.name == nil then
108-
print("couldn't parse this link: " .. str)
174+
quarto.log.warning("couldn't parse this link: " .. str)
109175
return {}
110176
end
111177

@@ -116,7 +182,7 @@ local function build_search_object(str)
116182
return search
117183
end
118184

119-
function report_broken_link(link, search_object, replacement)
185+
local function report_broken_link(link, search_object, replacement)
120186
-- TODO: how to unescape html elements like [?
121187
return pandoc.Code(pandoc.utils.stringify(link.content))
122188
end
@@ -154,7 +220,7 @@ function Link(link)
154220
return link
155221
end
156222

157-
function fixup_json(json, prefix)
223+
local function fixup_json(json, prefix)
158224
for _, item in ipairs(json.items) do
159225
item.uri = prefix .. item.uri
160226
end
@@ -167,11 +233,12 @@ return {
167233
local json
168234
local prefix
169235
for k, v in pairs(meta.interlinks.sources) do
170-
json = read_json(quarto.project.offset .. "/_inv/" .. k .. "_objects.json")
236+
local base_name = quarto.project.offset .. "/_inv/" .. k .. "_objects"
237+
json = read_inv_text_or_json(base_name)
171238
prefix = pandoc.utils.stringify(v.url)
172239
fixup_json(json, prefix)
173240
end
174-
json = read_json(quarto.project.offset .. "/objects.json")
241+
json = read_inv_text_or_json(quarto.project.offset .. "/objects")
175242
if json ~= nil then
176243
fixup_json(json, "/")
177244
end

docs/_quarto.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ website:
2828
text: Get Started
2929
- file: examples/
3030
text: Examples
31+
- file: tutorials/
32+
text: Tutorials
3133
- href: api/
3234
text: Reference
35+
3336
right:
3437
- icon: github
3538
href: https://github.com/machow/quartodoc/
200 KB
Loading
206 KB
Loading
203 KB
Loading
208 KB
Loading

0 commit comments

Comments
 (0)