diff --git a/.changeset/whole-taxis-follow.md b/.changeset/whole-taxis-follow.md new file mode 100644 index 0000000000..6f5995384b --- /dev/null +++ b/.changeset/whole-taxis-follow.md @@ -0,0 +1,5 @@ +--- +'myst-cli': patch +--- + +Applies the `myst-migrate` functions to embedded xref content diff --git a/packages/myst-cli/package.json b/packages/myst-cli/package.json index db48b4a5ef..327282d0fe 100644 --- a/packages/myst-cli/package.json +++ b/packages/myst-cli/package.json @@ -71,6 +71,7 @@ "myst-cli-utils": "^2.0.12", "myst-common": "^1.9.2", "myst-config": "^1.9.2", + "myst-migrate": "^1.7.0", "myst-execute": "^0.3.2", "myst-ext-button": "^0.0.1", "myst-ext-card": "^1.0.9", diff --git a/packages/myst-cli/src/transforms/crossReferences.ts b/packages/myst-cli/src/transforms/crossReferences.ts index a86aa60c6b..32ff1d98f4 100644 --- a/packages/myst-cli/src/transforms/crossReferences.ts +++ b/packages/myst-cli/src/transforms/crossReferences.ts @@ -9,6 +9,8 @@ import type { CrossReference, Dependency, Link, SourceFileKind } from 'myst-spec import type { ISession } from '../session/types.js'; import { loadFromCache, writeToCache } from '../session/cache.js'; import type { SiteAction, SiteExport } from 'myst-config'; +import { migrate } from 'myst-migrate'; +import { SPEC_VERSION } from '../spec-version.js'; export const XREF_MAX_AGE = 1; // in days @@ -58,6 +60,7 @@ async function fetchMystData( if (cacheData) { return JSON.parse(cacheData) as MystData; } + let data: MystData; try { const resp = await session.fetch(dataUrl); @@ -67,7 +70,36 @@ async function fetchMystData( data = (await resp.json()) as MystData; } catch { return onError('Could not load fetched data'); - // data is unset + } + + // Migrate external content if version differs from current + if (data.mdast && data.version !== undefined && data.version !== SPEC_VERSION) { + session.log.info( + `Migrating external content from v${data.version} to v${SPEC_VERSION} for ${urlSource}`, + ); + try { + const migrateFile = { + version: data.version, + mdast: data.mdast, + }; + + const migrated = await migrate(migrateFile, { + to: SPEC_VERSION, + log: session.log, + }); + + data.mdast = migrated.mdast; + data.version = migrated.version; + + session.log.debug( + `Migrated external content from v${migrateFile.version} to v${SPEC_VERSION} for ${urlSource}`, + ); + } catch (error) { + session.log.warn( + `Failed to migrate external content from v${data.version} to v${SPEC_VERSION}: ${error}`, + ); + // Continue with original content if migration fails + } } writeToCache(session, filename, JSON.stringify(data)); diff --git a/packages/mystmd/tests/notebook-fig-embed/outputs/index.json b/packages/mystmd/tests/notebook-fig-embed/outputs/index.json index a604e254a6..f7c868de76 100644 --- a/packages/mystmd/tests/notebook-fig-embed/outputs/index.json +++ b/packages/mystmd/tests/notebook-fig-embed/outputs/index.json @@ -1,4 +1,5 @@ { + "version": 3, "kind": "Article", "sha256": "f55f0890d64d1ed20bdaa8e6af9c0a50fb3bb729e4a11c0e9c89dc4f5fca2ccb", "slug": "index", @@ -20,7 +21,8 @@ "exports": [ { "format": "md", - "filename": "index.md" + "filename": "index.md", + "url": "/index-6f94b8993969cb04027606b5a32dba77.md" } ] }, @@ -41,13 +43,15 @@ "position": { "start": { "line": 3, "column": 1 }, "end": { "line": 3, "column": 1 } - } + }, + "key": "KH2zUG8u3f" } ], "identifier": "figure-directive-local", "label": "Figure directive - local", "html_id": "figure-directive-local", - "implicit": true + "implicit": true, + "key": "axK2NQZ4zO" }, { "type": "container", @@ -68,14 +72,14 @@ "hash": "a16fcedcd26437c820ccfc05d1f48a57", "path": "/a16fcedcd26437c820ccfc05d1f48a57.html" }, - "text/plain": { - "content": "alt.Chart(...)", - "content_type": "text/plain" - } + "text/plain": { "content": "alt.Chart(...)", "content_type": "text/plain" } } - } + }, + "children": [], + "key": "QJazaUG4dm" } - ] + ], + "key": "MbsKRKNyKE" }, { "type": "caption", @@ -93,11 +97,14 @@ "position": { "start": { "line": 7, "column": 1 }, "end": { "line": 7, "column": 1 } - } + }, + "key": "b0svqGHu3G" } - ] + ], + "key": "HOrpmKDLct" } - ] + ], + "key": "Le1CKCH5xu" } ], "enumerator": "1", @@ -107,7 +114,8 @@ "kind": "Notebook", "slug": "plot", "location": "/plot.ipynb" - } + }, + "key": "HiFvMsiM5E" }, { "type": "heading", @@ -123,13 +131,15 @@ "position": { "start": { "line": 10, "column": 1 }, "end": { "line": 10, "column": 1 } - } + }, + "key": "x2svglGSqy" } ], "identifier": "embed-directive-local", "label": "Embed directive - local", "html_id": "embed-directive-local", - "implicit": true + "implicit": true, + "key": "XGu9UfU69D" }, { "type": "embed", @@ -146,7 +156,8 @@ "lang": "python", "executable": true, "value": "points", - "enumerator": "1" + "enumerator": "1", + "key": "I8KaZvlXUY" }, { "type": "outputs", @@ -165,11 +176,15 @@ }, "text/plain": { "content": "alt.Chart(...)", "content_type": "text/plain" } } - } + }, + "children": [], + "key": "F0FppwUlIb" } - ] + ], + "key": "gvmleAToDt" } - ] + ], + "key": "okdCcNhScz" }, { "type": "heading", @@ -185,37 +200,45 @@ "position": { "start": { "line": 15, "column": 1 }, "end": { "line": 15, "column": 1 } - } + }, + "key": "DuP6QTzFkd" } ], "identifier": "figure-directive-external", "label": "Figure directive - external", "html_id": "figure-directive-external", - "implicit": true + "implicit": true, + "key": "BqMjKFS8va" }, { "type": "container", "kind": "figure", "children": [ { - "type": "output", - "data": [ + "type": "outputs", + "children": [ { - "output_type": "execute_result", - "execution_count": 2, - "metadata": {}, - "data": { - "text/html": { - "content_type": "text/html" - }, - "text/plain": { - "content": "alt.VConcatChart(...)", - "content_type": "text/plain" + "type": "output", + "jupyter_data": { + "output_type": "execute_result", + "execution_count": 2, + "metadata": {}, + "data": { + "text/html": { + "content_type": "text/html", + "hash": "280b61c8fba6a5767e2191500ef403d3", + "path": "https://cdn.curvenote.com/019afec0-1af0-7b31-8ccf-4f0dfa8cbd8c/public/280b61c8fba6a5767e2191500ef403d3.html" + }, + "text/plain": { + "content": "alt.VConcatChart(...)", + "content_type": "text/plain" + } } } } ], - "visibility": "show" + "visibility": "show", + "key": "FTN3p05PMS" }, { "type": "caption", @@ -233,11 +256,14 @@ "position": { "start": { "line": 19, "column": 1 }, "end": { "line": 19, "column": 1 } - } + }, + "key": "m0gu4rvLJH" } - ] + ], + "key": "yvjMKFtKeO" } - ] + ], + "key": "QZy8YhAHOs" } ], "enumerator": "2", @@ -248,8 +274,10 @@ "kind": "Notebook", "slug": "interactive-notebooks", "location": "/interactive-notebooks.ipynb", - "title": "Generate and Display Rich Outputs" - } + "title": "Generate and Display Rich Outputs", + "short_title": "Generate Rich Outputs" + }, + "key": "nb06UVJ4eS" }, { "type": "heading", @@ -265,13 +293,15 @@ "position": { "start": { "line": 22, "column": 1 }, "end": { "line": 22, "column": 1 } - } + }, + "key": "Z52HvWXDGn" } ], "identifier": "embed-directive-external", "label": "Embed directive - external", "html_id": "embed-directive-external", - "implicit": true + "implicit": true, + "key": "rwCTTgylzc" }, { "type": "embed", @@ -282,7 +312,8 @@ "kind": "Notebook", "slug": "interactive-notebooks", "location": "/interactive-notebooks.ipynb", - "title": "Generate and Display Rich Outputs" + "title": "Generate and Display Rich Outputs", + "short_title": "Generate Rich Outputs" }, "children": [ { @@ -290,34 +321,44 @@ "lang": "python", "executable": true, "value": "points & bars", + "visibility": "show", "enumerator": "1", - "visibility": "show" + "key": "d4dGQ2FQ7j" }, { - "type": "output", - "data": [ + "type": "outputs", + "children": [ { - "output_type": "execute_result", - "execution_count": 2, - "metadata": {}, - "data": { - "text/html": { - "content_type": "text/html" - }, - "text/plain": { - "content": "alt.VConcatChart(...)", - "content_type": "text/plain" + "type": "output", + "jupyter_data": { + "output_type": "execute_result", + "execution_count": 2, + "metadata": {}, + "data": { + "text/html": { + "content_type": "text/html", + "hash": "280b61c8fba6a5767e2191500ef403d3", + "path": "https://cdn.curvenote.com/019afec0-1af0-7b31-8ccf-4f0dfa8cbd8c/public/280b61c8fba6a5767e2191500ef403d3.html" + }, + "text/plain": { + "content": "alt.VConcatChart(...)", + "content_type": "text/plain" + } } } } ], - "visibility": "show" + "visibility": "show", + "key": "FTN3p05PMS" } - ] + ], + "key": "hr2VDiLTDh" } - ] + ], + "key": "YCERc1a73b" } - ] + ], + "key": "kr0hf7l3Pk" }, "references": { "cite": { "order": [], "data": {} } } }