File size: 695 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
export type JupyterLine = { type: "plaintext" | "image"; content: string };

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

  for (const line of content.split("\n")) {
    if (line.startsWith("![image](data:image/png;base64,")) {
      if (currentText) {
        lines.push({ type: "plaintext", content: currentText });
        currentText = ""; // Reset after pushing plaintext
      }
      lines.push({ type: "image", content: line });
    } else {
      currentText += `${line}\n`;
    }
  }

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

  return lines;
};