File size: 699 Bytes
b59aa07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export type JupyterLine = {
  type: "plaintext" | "image";
  content: string;
  url?: string;
};

export const parseCellContent = (content: string, imageUrls?: string[]) => {
  const lines: JupyterLine[] = [];
  let currentText = "";

  // First, process the text content
  for (const line of content.split("\n")) {
    currentText += `${line}\n`;
  }

  if (currentText) {
    lines.push({ type: "plaintext", content: currentText });
  }

  // Then, add image lines if we have image URLs
  if (imageUrls && imageUrls.length > 0) {
    imageUrls.forEach((url) => {
      lines.push({
        type: "image",
        content: `![image](${url})`,
        url,
      });
    });
  }

  return lines;
};