Skip to content

Commit

Permalink
fix: upgrade xrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Nov 20, 2024
1 parent 90e6f2a commit 9b92238
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/myst-cli/src/transforms/crossReferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { VFile } from 'vfile';
import { selectAll } from 'unist-util-select';
import { visit } from 'unist-util-visit';
import type { FrontmatterParts, GenericNode, GenericParent, References } from 'myst-common';
import { RuleId, fileWarn, plural, selectMdastNodes } from 'myst-common';
import { computeHash, tic } from 'myst-cli-utils';
Expand Down Expand Up @@ -32,6 +33,24 @@ export type MystData = {
references?: References;
};

function upgradeMystData(data: MystData): MystData {
// Visit outputs
visit(
data.mdast as any,
'output',
(node: GenericNode, index: number | null, parent: GenericParent | null) => {
if (parent && parent.type !== 'outputs') {
const outputs = {
type: 'outputs',
children: [node],
};
parent.children[index!] = outputs;
}
},
);
return data;
}

async function fetchMystData(
session: ISession,
dataUrl: string | undefined,
Expand All @@ -48,7 +67,8 @@ async function fetchMystData(
try {
const resp = await session.fetch(dataUrl);
if (resp.ok) {
const data = (await resp.json()) as MystData;
const data = upgradeMystData((await resp.json()) as MystData);

writeToCache(session, filename, JSON.stringify(data));
return data;
}
Expand Down

0 comments on commit 9b92238

Please sign in to comment.