This repository was archived by the owner on Mar 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Switch to quarto for docs #799
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8c35e79
removed old docs
epinzur 03017b8
added new docs
epinzur 35f200c
setup docs env and ci
epinzur 9e9c66b
edited docstrings
epinzur 08f64eb
fix build
epinzur d06c07f
fix lint
epinzur 4377354
try building without nox
epinzur fbcd747
added missing template
epinzur 257473e
minor tweaks from getting started
bjchambers f57e1ea
docs: Add community page
bjchambers 9ee8273
made some quarto tweaks (#801)
epinzur 016e717
update dependencies after rebase
epinzur 8200eea
Add doc linting to quarto docs (#805)
epinzur 4ce0fb9
fixed issues
epinzur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| _build | ||
| .jupyter_cache | ||
| jupyter_execute | ||
| source/reference/apidocs | ||
| source/iframe_figures | ||
| # quarto build cache | ||
| /.quarto/ | ||
|
|
||
| # quartodoc interlink artifacts | ||
| /_inv/ | ||
| /objects.json | ||
|
|
||
| # generated API docs | ||
| /reference/ | ||
|
|
||
| # files that might remain if a quarto build is interrupted | ||
| index.html | ||
| /blog/*.html | ||
| /examples/*.html | ||
| /guide/*.html | ||
| index-listing.json | ||
| data_types-listing.json | ||
| /site_libs/ | ||
|
|
||
| # output of the site from `nox -s docs-build` | ||
| /_site/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.html | ||
epinzur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| *_files/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| title: Interlinks | ||
| author: Michael Chow | ||
| version: 1.1.0 | ||
| quarto-required: ">=1.2.0" | ||
| contributes: | ||
| filters: | ||
| - interlinks.lua |
254 changes: 254 additions & 0 deletions
254
python/docs/_extensions/machow/interlinks/interlinks.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,254 @@ | ||
| local function read_inv_text(filename) | ||
| -- read file | ||
| local file = io.open(filename, "r") | ||
| if file == nil then | ||
| return nil | ||
| end | ||
| local str = file:read("a") | ||
| file:close() | ||
|
|
||
|
|
||
| local project = str:match("# Project: (%S+)") | ||
| local version = str:match("# Version: (%S+)") | ||
|
|
||
| local data = {project = project, version = version, items = {}} | ||
|
|
||
| local ptn_data = | ||
| "^" .. | ||
| "(.-)%s+" .. -- name | ||
| "([%S:]-):" .. -- domain | ||
| "([%S]+)%s+" .. -- role | ||
| "(%-?%d+)%s+" .. -- priority | ||
| "(%S*)%s+" .. -- uri | ||
| "(.-)\r?$" -- dispname | ||
|
|
||
|
|
||
| -- Iterate through each line in the file content | ||
| for line in str:gmatch("[^\r\n]+") do | ||
| if not line:match("^#") then | ||
| -- Match each line against the pattern | ||
| local name, domain, role, priority, uri, dispName = line:match(ptn_data) | ||
|
|
||
| -- if name is nil, raise an error | ||
| if name == nil then | ||
| error("Error parsing line: " .. line) | ||
| end | ||
|
|
||
| data.items[#data.items + 1] = { | ||
| name = name, | ||
| domain = domain, | ||
| role = role, | ||
| priority = priority, | ||
| uri = uri, | ||
| dispName = dispName | ||
| } | ||
| end | ||
| end | ||
| return data | ||
| end | ||
|
|
||
| local function read_json(filename) | ||
|
|
||
| local file = io.open(filename, "r") | ||
| if file == nil then | ||
| return nil | ||
| end | ||
| local str = file:read("a") | ||
| file:close() | ||
|
|
||
| local decoded = quarto.json.decode(str) | ||
| return decoded | ||
| end | ||
|
|
||
| local function read_inv_text_or_json(base_name) | ||
| local file = io.open(base_name .. ".txt", "r") | ||
| if file then | ||
| -- TODO: refactors so we don't just close the file immediately | ||
| io.close(file) | ||
| json = read_inv_text(base_name .. ".txt") | ||
|
|
||
| else | ||
| json = read_json(base_name .. ".json") | ||
| end | ||
|
|
||
| return json | ||
| end | ||
|
|
||
| local inventory = {} | ||
|
|
||
| local function lookup(search_object) | ||
|
|
||
| local results = {} | ||
| 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 | ||
| end | ||
|
|
||
| if item.name ~= search_object.name then | ||
| goto continue | ||
| end | ||
|
|
||
| if search_object.role and item.role ~= search_object.role then | ||
| goto continue | ||
| end | ||
|
|
||
| if search_object.domain and item.domain ~= search_object.domain then | ||
| goto continue | ||
| else | ||
| if search_object.domain or item.domain == "py" then | ||
| table.insert(results, item) | ||
| end | ||
|
|
||
| goto continue | ||
| end | ||
|
|
||
| ::continue:: | ||
| end | ||
| end | ||
|
|
||
| if #results == 1 then | ||
| return results[1] | ||
| end | ||
| if #results > 1 then | ||
| quarto.log.warning("Found multiple matches for " .. search_object.name .. ", using the first match.") | ||
| return results[1] | ||
| end | ||
| if #results == 0 then | ||
| quarto.log.warning("Found no matches for object:\n", search_object) | ||
| end | ||
|
|
||
| return nil | ||
| end | ||
|
|
||
| local function mysplit (inputstr, sep) | ||
| if sep == nil then | ||
| sep = "%s" | ||
| end | ||
| local t={} | ||
| for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | ||
| table.insert(t, str) | ||
| end | ||
| return t | ||
| end | ||
|
|
||
| local function normalize_role(role) | ||
| if role == "func" then | ||
| return "function" | ||
| end | ||
| return role | ||
| end | ||
|
|
||
| local function build_search_object(str) | ||
| local starts_with_colon = str:sub(1, 1) == ":" | ||
| local search = {} | ||
| if starts_with_colon then | ||
| local t = mysplit(str, ":") | ||
| if #t == 2 then | ||
| -- e.g. :py:func:`my_func` | ||
| search.role = normalize_role(t[1]) | ||
| search.name = t[2]:match("%%60(.*)%%60") | ||
| elseif #t == 3 then | ||
| -- e.g. :py:func:`my_func` | ||
| search.domain = t[1] | ||
| search.role = normalize_role(t[2]) | ||
| search.name = t[3]:match("%%60(.*)%%60") | ||
| elseif #t == 4 then | ||
| -- e.g. :ext+inv:py:func:`my_func` | ||
| search.external = true | ||
|
|
||
| search.inv_name = t[1]:match("external%+(.*)") | ||
| search.domain = t[2] | ||
| search.role = normalize_role(t[3]) | ||
| search.name = t[4]:match("%%60(.*)%%60") | ||
| else | ||
| quarto.log.warning("couldn't parse this link: " .. str) | ||
| return {} | ||
| end | ||
| else | ||
| search.name = str:match("%%60(.*)%%60") | ||
| end | ||
|
|
||
| if search.name == nil then | ||
| quarto.log.warning("couldn't parse this link: " .. str) | ||
| return {} | ||
| end | ||
|
|
||
| if search.name:sub(1, 1) == "~" then | ||
| search.shortened = true | ||
| search.name = search.name:sub(2, -1) | ||
| end | ||
| return search | ||
| end | ||
|
|
||
| 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 | ||
|
|
||
| function Link(link) | ||
| -- do not process regular links ---- | ||
| if not link.target:match("%%60") then | ||
| return link | ||
| end | ||
|
|
||
| -- lookup item ---- | ||
| local search = build_search_object(link.target) | ||
| local item = lookup(search) | ||
|
|
||
| -- determine replacement, used if no link text specified ---- | ||
| local original_text = pandoc.utils.stringify(link.content) | ||
| local replacement = search.name | ||
| if search.shortened then | ||
| local t = mysplit(search.name, ".") | ||
| replacement = t[#t] | ||
| end | ||
|
|
||
| -- set link text ---- | ||
| if original_text == "" and replacement ~= nil then | ||
| link.content = pandoc.Code(replacement) | ||
| end | ||
|
|
||
| -- report broken links ---- | ||
| if item == nil then | ||
| return report_broken_link(link, search) | ||
| end | ||
| link.target = item.uri:gsub("%$$", search.name) | ||
|
|
||
|
|
||
| return link | ||
| end | ||
|
|
||
| local function fixup_json(json, prefix) | ||
| for _, item in ipairs(json.items) do | ||
| item.uri = prefix .. item.uri | ||
| end | ||
| table.insert(inventory, json) | ||
| end | ||
|
|
||
| return { | ||
| { | ||
| Meta = function(meta) | ||
| local json | ||
| local prefix | ||
| if meta.interlinks and meta.interlinks.sources then | ||
| for k, v in pairs(meta.interlinks.sources) do | ||
| local base_name = quarto.project.offset .. "/_inv/" .. k .. "_objects" | ||
| json = read_inv_text_or_json(base_name) | ||
| prefix = pandoc.utils.stringify(v.url) | ||
| if json ~= nil then | ||
| fixup_json(json, prefix) | ||
| end | ||
| end | ||
| end | ||
| json = read_inv_text_or_json(quarto.project.offset .. "/objects") | ||
| if json ~= nil then | ||
| fixup_json(json, "/") | ||
| end | ||
| end | ||
| }, | ||
| { | ||
| Link = Link | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.