Skip to content

Commit

Permalink
🔗 Improve intersphinx linking (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Jun 15, 2023
1 parent 0410d19 commit 92fd39d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-pigs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-transforms': patch
---

Allow intersphinx to connect without a target
29 changes: 14 additions & 15 deletions packages/myst-transforms/src/links/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,38 @@ export class MystTransformer implements LinkTransformer {
});
return false;
}
if (!url.hash) {
fileError(file, `Must provide a target for "${urlSource}"`, {
node: link,
note: 'Use the `#` symbol to create a target, for example, <myst:project#my-target>',
source: TRANSFORM_SOURCE,
});
return false;
}
const target = url.hash.replace(/^#/, '');
const lookup = this.intersphinx.find((i) => {
const target = url.hash?.replace(/^#/, '') ?? '';
const project = this.intersphinx.find((i) => {
if (url.pathname) return i.id === url.pathname;
// If the pathname is not specified, check if it has the target
return !!i.getEntry({ name: target });
if (target) return !!i.getEntry({ name: target });
return false;
});
if (!lookup) {
if (!project || !project.path) {
fileWarn(file, `Unknown project "${url.pathname}" for link: ${urlSource}`, {
node: link,
source: TRANSFORM_SOURCE,
});
return false;
}
if (!url.hash) {
link.internal = false;
link.url = project.path;
updateLinkTextIfEmpty(link, project.id || '(see documentation)');
return false;
}
// TODO: add query params in here to pick the domain
const entry = lookup.getEntry({ name: target });
const entry = project.getEntry({ name: target });
if (!entry) {
fileWarn(file, `"${urlSource}" not found intersphinx ${lookup.id} (${lookup.path})`, {
fileWarn(file, `"${urlSource}" not found intersphinx ${project.id} (${project.path})`, {
node: link,
source: TRANSFORM_SOURCE,
});
return false;
}
link.internal = false;
link.url = entry.location;
updateLinkTextIfEmpty(link, entry.display || lookup.id || '(see documentation)');
updateLinkTextIfEmpty(link, entry.display || project.id || '(see documentation)');
return true;
}
}

0 comments on commit 92fd39d

Please sign in to comment.