Skip to content

Commit

Permalink
🔗 Add remote cross-project link to AST (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored May 8, 2024
1 parent 8463044 commit da9ca5b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/hip-readers-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"myst-transforms": patch
"myst-spec-ext": patch
---

Add remote base URL for the external links to help with recursion!
1 change: 1 addition & 0 deletions packages/myst-spec-ext/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,6 @@ export type Aside = Node & {

export type CrossReference = SpecCrossReference & {
remote?: boolean;
remoteBaseUrl?: string;
html_id?: string;
};
2 changes: 0 additions & 2 deletions packages/myst-transforms/src/links/myst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ describe('Test MystTransformer', () => {
expect(t.test(link.url)).toBe(true);
expect(t.transform(link, file)).toBe(true);
expect(file.messages.length).toEqual(0);
expect(link.internal).toBe(false);
expect(link.url).toEqual('https://example.com/myst-ref/my-figure');
expect(link.dataUrl).toEqual('https://example.com/myst-ref/my-figure.json');
expect(link.type).toEqual('crossReference');
Expand Down Expand Up @@ -316,7 +315,6 @@ describe('Test MystTransformer', () => {
expect(t.test(link.url)).toBe(true);
expect(t.transform(link, file)).toBe(true);
expect(file.messages.length).toEqual(0);
expect(link.internal).toBe(false);
expect(link.url).toEqual('https://example.com/myst-ref/');
expect(link.dataUrl).toEqual('https://example.com/myst-ref/index.json');
expect(link.type).toEqual('crossReference');
Expand Down
5 changes: 3 additions & 2 deletions packages/myst-transforms/src/links/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ export class MystTransformer implements LinkTransformer {
) {
link.children = [];
}
link.internal = false;
link.url = `${mystXRefs.url}${match.url}`;
link.dataUrl = `${mystXRefs.url}${match.data}`;
if (match.kind === 'page') {
link.protocol = 'file';
// TODO: We should move this to be a cross-reference as well with kind "page"
link.internal = false;
} else {
const xref = link as unknown as CrossReference;
// Upgrade links to cross-references with identifiers
xref.type = 'crossReference';
xref.remote = true;
xref.remoteBaseUrl = mystXRefs.url;
xref.identifier = match.identifier;
xref.label = match.identifier;
xref.html_id = match.html_id;
Expand Down
1 change: 0 additions & 1 deletion packages/myst-transforms/src/links/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('Link Plugin Transformer', () => {
};
linksTransform({ type: 'root', children: [link] }, file, { transformers: [t] });
expect(file.messages.length).toEqual(0);
expect(link.internal).toBe(false);
expect(link.url).toEqual('https://example.com/myst-ref/my-figure');
expect(link.dataUrl).toEqual('https://example.com/myst-ref/my-figure.json');
expect(link.type).toEqual('crossReference');
Expand Down

0 comments on commit da9ca5b

Please sign in to comment.