Skip to content

Commit ee85d11

Browse files
committed
fix: only label first code and outputs
1 parent f8c584f commit ee85d11

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

packages/myst-transforms/src/blocks.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,12 @@ export function blockMetadataTransform(mdast: GenericParent, file: VFile) {
8080
}
8181
}
8282
if (block.identifier) {
83-
const codeChildren = selectAll('code', block) as Code[];
84-
codeChildren.forEach((child, index) => {
85-
if (child.identifier) return;
86-
if (codeChildren.length === 1) {
87-
child.identifier = `${block.identifier}-code`;
88-
} else {
89-
child.identifier = `${block.identifier}-code-${index}`;
90-
}
91-
});
83+
const codeNode = selectAll('code', block) as any as Code | null;
84+
if (codeNode !== null && !codeNode.identifier) {
85+
codeNode.identifier = `${block.identifier}-code`;
86+
}
9287
const outputsNode = select('outputs', block) as GenericNode | undefined;
93-
if (outputsNode && !outputsNode.identifier) {
88+
if (outputsNode !== undefined && !outputsNode.identifier) {
9489
// Label outputs node
9590
outputsNode.identifier = `${block.identifier}-output`;
9691
// Enumerate outputs

0 commit comments

Comments
 (0)