Skip to content

Commit b6b8b37

Browse files
committed
correct handling of multiple attachments in Jupyter Notebook classic
1 parent 8399fb9 commit b6b8b37

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

news/changelog-1.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Correctly interpret cell metadata with `false` values
55
- Render text/latex outputs consisting entirely of $ math as markdown math
66
- Use IPython 7.14 import syntax in `ojs_define`
7+
- Correct handling of multiple attachments in Jupyter Notebook classic
78

89
## OJS
910

src/core/jupyter/jupyter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,13 +755,15 @@ export function mdFromContentCell(
755755
if (options && cell.attachments && cell.source) {
756756
// close source so we can modify it
757757
const source = ld.cloneDeep(cell.source) as string[];
758-
// process each file attachment
759-
Object.keys(cell.attachments).forEach((file) => {
758+
// process each file attachment (ensure we have a cell id for uniqueness)
759+
const cellId = cell.id || shortUuid();
760+
Object.keys(cell.attachments).forEach((file, index) => {
760761
const attachment = cell.attachments![file];
761762
for (const mimeType of Object.keys(attachment)) {
762763
if (extensionForMimeImageType(mimeType, undefined)) {
763764
// save attachment in the figures dir
764-
const imageFile = options.assets.figures_dir + "/" + file;
765+
const imageFile = options.assets.figures_dir +
766+
`/${cellId}-${index + 1}-${file}`;
765767
const outputFile = join(options.assets.base_dir, imageFile);
766768
ensureDirSync(dirname(outputFile));
767769
const data = attachment[mimeType];

0 commit comments

Comments
 (0)