Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/whole-taxis-follow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Applies the `myst-migrate` functions to embedded xref content
1 change: 1 addition & 0 deletions packages/myst-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 33 additions & 1 deletion packages/myst-cli/src/transforms/crossReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down
159 changes: 100 additions & 59 deletions packages/mystmd/tests/notebook-fig-embed/outputs/index.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": 3,
"kind": "Article",
"sha256": "f55f0890d64d1ed20bdaa8e6af9c0a50fb3bb729e4a11c0e9c89dc4f5fca2ccb",
"slug": "index",
Expand All @@ -20,7 +21,8 @@
"exports": [
{
"format": "md",
"filename": "index.md"
"filename": "index.md",
"url": "/index-6f94b8993969cb04027606b5a32dba77.md"
}
]
},
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -93,11 +97,14 @@
"position": {
"start": { "line": 7, "column": 1 },
"end": { "line": 7, "column": 1 }
}
},
"key": "b0svqGHu3G"
}
]
],
"key": "HOrpmKDLct"
}
]
],
"key": "Le1CKCH5xu"
}
],
"enumerator": "1",
Expand All @@ -107,7 +114,8 @@
"kind": "Notebook",
"slug": "plot",
"location": "/plot.ipynb"
}
},
"key": "HiFvMsiM5E"
},
{
"type": "heading",
Expand All @@ -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",
Expand All @@ -146,7 +156,8 @@
"lang": "python",
"executable": true,
"value": "points",
"enumerator": "1"
"enumerator": "1",
"key": "I8KaZvlXUY"
},
{
"type": "outputs",
Expand All @@ -165,11 +176,15 @@
},
"text/plain": { "content": "alt.Chart(...)", "content_type": "text/plain" }
}
}
},
"children": [],
"key": "F0FppwUlIb"
}
]
],
"key": "gvmleAToDt"
}
]
],
"key": "okdCcNhScz"
},
{
"type": "heading",
Expand All @@ -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",
Expand All @@ -233,11 +256,14 @@
"position": {
"start": { "line": 19, "column": 1 },
"end": { "line": 19, "column": 1 }
}
},
"key": "m0gu4rvLJH"
}
]
],
"key": "yvjMKFtKeO"
}
]
],
"key": "QZy8YhAHOs"
}
],
"enumerator": "2",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -282,42 +312,53 @@
"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": [
{
"type": "code",
"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": {} } }
}
Loading