Skip to content

Commit 0e96353

Browse files
committed
support cell previews with layout
1 parent f2e6efa commit 0e96353

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/format/html/format-html-notebook.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,30 @@ export function notebookViewPostProcessor() {
6868
decoratorNode.appendChild(contentsEl);
6969

7070
containerNode.appendChild(decoratorNode);
71-
cell.parentElement?.insertBefore(containerNode, cell);
72-
containerNode.appendChild(cell);
71+
72+
const prevSibling = cellEl.previousElementSibling;
73+
if (
74+
prevSibling &&
75+
prevSibling.tagName === "DIV" &&
76+
prevSibling.classList.contains("cell-code")
77+
) {
78+
// If the previous sibling is a cell-code, that is the code cell
79+
// for this output and we should grab it too
80+
cell.parentElement?.insertBefore(containerNode, cell);
81+
82+
// Grab the previous element too
83+
const wrapperDiv = doc.createElement("div");
84+
containerNode.appendChild(wrapperDiv);
85+
86+
// move the cells
87+
wrapperDiv.appendChild(prevSibling.cloneNode(true));
88+
prevSibling.remove();
89+
90+
wrapperDiv.appendChild(cell);
91+
} else {
92+
cell.parentElement?.insertBefore(containerNode, cell);
93+
containerNode.appendChild(cell);
94+
}
7395
}
7496
}
7597

0 commit comments

Comments
 (0)