From da9ca5b27025ce0180eb15992583f57e790fd7ff Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Wed, 8 May 2024 10:02:09 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=97=20Add=20remote=20cross-project=20l?= =?UTF-8?q?ink=20to=20AST=20(#1187)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/hip-readers-taste.md | 6 ++++++ packages/myst-spec-ext/src/types.ts | 1 + packages/myst-transforms/src/links/myst.spec.ts | 2 -- packages/myst-transforms/src/links/myst.ts | 5 +++-- packages/myst-transforms/src/links/plugin.spec.ts | 1 - 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/hip-readers-taste.md diff --git a/.changeset/hip-readers-taste.md b/.changeset/hip-readers-taste.md new file mode 100644 index 000000000..0fe8c00af --- /dev/null +++ b/.changeset/hip-readers-taste.md @@ -0,0 +1,6 @@ +--- +"myst-transforms": patch +"myst-spec-ext": patch +--- + +Add remote base URL for the external links to help with recursion! diff --git a/packages/myst-spec-ext/src/types.ts b/packages/myst-spec-ext/src/types.ts index f1eaf4bf7..ce1afe2d2 100644 --- a/packages/myst-spec-ext/src/types.ts +++ b/packages/myst-spec-ext/src/types.ts @@ -256,5 +256,6 @@ export type Aside = Node & { export type CrossReference = SpecCrossReference & { remote?: boolean; + remoteBaseUrl?: string; html_id?: string; }; diff --git a/packages/myst-transforms/src/links/myst.spec.ts b/packages/myst-transforms/src/links/myst.spec.ts index 455a47f54..220bab86c 100644 --- a/packages/myst-transforms/src/links/myst.spec.ts +++ b/packages/myst-transforms/src/links/myst.spec.ts @@ -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'); @@ -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'); diff --git a/packages/myst-transforms/src/links/myst.ts b/packages/myst-transforms/src/links/myst.ts index 18c3cc123..0064e51f6 100644 --- a/packages/myst-transforms/src/links/myst.ts +++ b/packages/myst-transforms/src/links/myst.ts @@ -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; diff --git a/packages/myst-transforms/src/links/plugin.spec.ts b/packages/myst-transforms/src/links/plugin.spec.ts index b6a31225d..b5a578113 100644 --- a/packages/myst-transforms/src/links/plugin.spec.ts +++ b/packages/myst-transforms/src/links/plugin.spec.ts @@ -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');