Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(notebooks): keep markdown tables in the passage they belong to (#80727)

Sinan Kucukkoselercac116e7bcc9
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 9386d83dbd0d..48bb99e40098 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1280,6 +1280,10 @@ snapshots:
hash: v1.k794b7964.e6d1431f2c287222b95e12de13466b613f13602baf25cf0992c1cd0567c93832.Lr1GWE4QycbyRnEu3qFN0pRr6dXkOKnLMzBiG5W61tw
components-markdown-notebook--slash-menu-and-insertion--light:
hash: v1.k794b7964.bd761ee9ca4ca6234cdb1010e654ffb858f8f3768908fcd19e1622e33ded5db2.1V0PtJ0cd648-epvNF70aK-NWlnml71MG1wAapku6sY
+ components-markdown-notebook--tables-in-prose--dark:
+ hash: v1.k794b7964.a13a637d5833b26653523a319666fcfa3f549b8fcb9aeb8578d2cbc90ace419c.xxBNxMqNgoZhMl81EacW5YuJNOtvuk5KpH4C9O692lc
+ components-markdown-notebook--tables-in-prose--light:
+ hash: v1.k794b7964.beed90b19074cc9e07f6223c688ab0f938b077f7cab6612e4bebc37245310fbb.-77ktUbDCicNpcBxW-bLiAGCRyxNy9yVhfCUxNeC874
components-markdown-notebook--text-only-notebook--dark:
hash: v1.k794b7964.0736ade6a331a708ee3b7b6e393ec3f1d38e8bd62729d4ab67a4dc7080f62a02.zdPGKStU_sTO5KCpsDq66BEJMWx-ufUTiB0auOiVDFw
components-markdown-notebook--text-only-notebook--light:
@@ -6627,9 +6631,9 @@ snapshots:
scenes-app-notebooks--empty-notebook--light:
hash: v1.k794b7964.77aff40362510d2b0372862354b4a55a23ec608def9080f978ee0422a42be781.53nBm8cpvK5A2HhLidaodgMOlw4BlMJlzDqUCf33Gsc
scenes-app-notebooks--flattened-table--dark:
- hash: v1.k794b7964.677ede582bed9c869565e1243d26a9651c5021aec2ec41c7c1d3f724538ca843.JIPEWABxzn_aVKEMxVQUpBbwiLP7WdQKBZ1kVZvCgfw
+ hash: v1.k794b7964.ef2e6fa108d6aedc7a660ec0f9929b4362c468b474c6eb96eb3a996d539d77f0.8fZcPL5ZbcePeweEDx5nwAdc1K8naAXwCSl6A38LWg4
scenes-app-notebooks--flattened-table--light:
- hash: v1.k794b7964.3003771ef6f5988152880ef8ed616a46419f2eb13a8aa84cf7562d73ba56e6a9.15cAbTKrrcaBv-cerYOLfrOKp-8wyTwwzHrr-Nt6zpg
+ hash: v1.k794b7964.76aadf2d94b340adedffadff6261c3c6dc7350883520fda101752e4021994219.n685ASmlzDTxjja7xjZfNGAksD7Ap99kalcxxxdJ0Yw
scenes-app-notebooks--headings--dark:
hash: v1.k794b7964.59254db5c596295bcea25ba1937594bb6654feae3d64fedfcd6681ceab6c4a2c.OghyG8OZyiZQKT2uGKJ1huWUb9PYvEssauVMYICjkbk
scenes-app-notebooks--headings--light:
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
index 2bc281897a8d..8d95bf919433 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.scss
@@ -1163,6 +1163,31 @@ h3.MarkdownNotebook__text-block--heading {
border-left-color: var(--markdown-notebook-table-gutter);
}
+/* A table inside a text group sits on the card that already carries the prose, so it drops the
+ card chrome and keeps only the grid's own outline. The background is left alone because it
+ already matches the card, and overriding it here would also cancel the AI-writing highlight. */
+.MarkdownNotebook__text-group .MarkdownNotebook__table-block {
+ margin: 0.5rem 0;
+ border: 1px solid var(--markdown-notebook-table-divider);
+ border-radius: 0.25rem;
+ box-shadow: none;
+}
+
+.MarkdownNotebook__text-group .MarkdownNotebook__table-block:focus-within {
+ border-color: color-mix(in sRGB, var(--primary) 34%, var(--markdown-notebook-table-divider));
+}
+
+/* A standalone table rounds its right corners only, because its left edge is the card gutter.
+ Inside a group both edges are the grid, so the left corners round too. */
+.MarkdownNotebook__text-group .MarkdownNotebook__table-block th:first-child {
+ border-top-left-radius: calc(0.25rem - 1px);
+}
+
+.MarkdownNotebook__text-group .MarkdownNotebook__table-block tbody tr:last-child td:first-child,
+.MarkdownNotebook__text-group .MarkdownNotebook__table-block table:not(:has(tbody tr)) th:first-child {
+ border-bottom-left-radius: calc(0.25rem - 1px);
+}
+
.MarkdownNotebook__list-block {
box-sizing: border-box;
width: calc(100% - var(--markdown-notebook-content-offset));
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx
index b7d37c163b61..c159981e332b 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.stories.tsx
@@ -221,6 +221,34 @@ export const ListsAndLinks: Story = {
},
}
+export const TablesInProse: Story = {
+ args: {
+ value: `## Weekly activation review
+
+Signup completion improved after the onboarding changes.
+
+| Step | Completion | Change |
+| --- | ---: | ---: |
+| Signup form | 82% | +4% |
+| Workspace setup | 61% | +1% |
+
+Both tables above and below belong to this passage, so they share its card.
+
+| Segment | Invite acceptance |
+| --- | ---: |
+| Self-serve | 44% |
+| Enterprise | 71% |
+
+The table below was added as a node of its own, so it keeps a card of its own.
+
+
+| Owner | Follow-up |
+| --- | --- |
+| Growth | Retry the invite email |
+| Onboarding | Shorten the setup step |`,
+ },
+}
+
export const QueryBlock: Story = {
args: {
value: queryNotebook,
diff --git a/frontend/src/lib/components/MarkdownNotebook/README.md b/frontend/src/lib/components/MarkdownNotebook/README.md
index 67a5ad33faa5..70455e7a40ed 100644
--- a/frontend/src/lib/components/MarkdownNotebook/README.md
+++ b/frontend/src/lib/components/MarkdownNotebook/README.md
@@ -32,7 +32,9 @@ Inline: bold (`**`/`__`), italic (`*`/`_`, underscores only at word boundaries),
## Visual grouping
-Consecutive text-like blocks (paragraphs, headings, lists, blockquotes, code blocks) render inside one shared card surface — a _text group_ (`getMarkdownNotebookVisualGroups` in `documentModel.ts`). Within a group, blockquote runs and code blocks form their own tinted sub-surfaces (`MarkdownNotebookTextSurface`: `text` | `quote` | `code`); a surface that starts or ends its group stretches flush to the card edge. Components, tables, and dividers render as standalone rows between groups.
+Consecutive text-like blocks (paragraphs, headings, lists, blockquotes, code blocks) render inside one shared card surface — a _text group_ (`getMarkdownNotebookVisualGroups` in `documentModel.ts`). Within a group, blockquote runs and code blocks form their own tinted sub-surfaces (`MarkdownNotebookTextSurface`: `text` | `quote` | `code`); a surface that starts or ends its group stretches flush to the card edge. Components and dividers render as standalone rows between groups.
+
+A table joins a card an earlier block already opened, but never opens one itself (`tableJoinsTextGroup`). A table written between two paragraphs therefore reads as part of that passage: it joins the `text` surface and drops its card chrome, keeping only the grid outline. A table carrying a card boundary, or following a standalone block, keeps its own row and its own chrome.
A block carrying `startsGroup` breaks out of the run above it and starts its own card. It is set when the block was added as a node in its own right rather than typed as a continuation: the insert boundary's "+", an MCP `notebooks-add-cell` insert, `appendMarkdownNotebookBlock`. Enter inside a card keeps making blocks in that same card, so the two stay distinguishable. The flag lives in the markdown as a **second blank line** before the block (`NOTEBOOK_BLOCK_SEPARATOR`) — nothing else would survive a save, since markdown is the only storage. It never applies to the first block, which has no separator to widen.
diff --git a/frontend/src/lib/components/MarkdownNotebook/documentModel.test.ts b/frontend/src/lib/components/MarkdownNotebook/documentModel.test.ts
index 5538a6f7f646..3aa500658fbd 100644
--- a/frontend/src/lib/components/MarkdownNotebook/documentModel.test.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/documentModel.test.ts
@@ -1,7 +1,49 @@
-import { rekeyNotebookNodes } from './documentModel'
+import { getMarkdownNotebookVisualGroups, rekeyNotebookNodes } from './documentModel'
+import { parseMarkdownNotebook } from './markdown'
import { NotebookBlockNode } from './types'
describe('documentModel', () => {
+ describe('getMarkdownNotebookVisualGroups', () => {
+ it('keeps a table written between paragraphs inside the surrounding text group', () => {
+ const document = parseMarkdownNotebook(
+ [
+ 'Signup completion improved after the onboarding changes.',
+ '',
+ '| Step | Completion |',
+ '| --- | ---: |',
+ '| Signup form | 82% |',
+ '',
+ 'Workspace setup is the step to watch next.',
+ ].join('\n')
+ )
+
+ const groups = getMarkdownNotebookVisualGroups(document.nodes)
+
+ expect(groups).toHaveLength(1)
+ expect(groups[0].type === 'text' ? groups[0].items.map((item) => item.node.type) : []).toEqual([
+ 'paragraph',
+ 'table',
+ 'paragraph',
+ ])
+ })
+
+ it('keeps a table inserted as its own node standing alone', () => {
+ const document = parseMarkdownNotebook(
+ [
+ 'Signup completion improved after the onboarding changes.',
+ '',
+ '',
+ '| Step | Completion |',
+ '| --- | ---: |',
+ ].join('\n')
+ )
+
+ const groups = getMarkdownNotebookVisualGroups(document.nodes)
+
+ expect(groups.map((group) => group.type)).toEqual(['text', 'block'])
+ })
+ })
+
describe('rekeyNotebookNodes', () => {
it('gives a pasted component node a fresh nodeId so it no longer shares logic with the original', () => {
// A trend chart carrying a persisted nodeId, as it exists once saved and copied.
diff --git a/frontend/src/lib/components/MarkdownNotebook/documentModel.ts b/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
index 3457aee39dca..f4e5e769f957 100644
--- a/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
@@ -51,8 +51,9 @@ export type MarkdownNotebookVisualGroup =
index: number
}
-/** Blocks that share a card with the text-like blocks around them. Components, tables, and
- * dividers always stand alone, so they never need a `startsGroup` boundary. */
+/** Blocks that open a card of their own and share it with the text-like blocks that follow.
+ * Components, tables, and dividers never open one, so they need no `startsGroup` boundary.
+ * A table can still join a card an earlier block opened, see `tableJoinsTextGroup`. */
export function isTextGroupNode(node: NotebookBlockNode | undefined): boolean {
return (
!!node && (isTextBlockNode(node) || node.type === 'list' || node.type === 'code' || isPromptComponentNode(node))
@@ -83,9 +84,19 @@ export function getMarkdownNotebookVisualGroups(
return isTextGroupNode(nodes[nextIndex])
}
+ // A table written between paragraphs reads as part of that passage, so it joins the card the
+ // text above it opened. A table that carries a card boundary (an insert-menu or MCP insert),
+ // or that follows a standalone block, keeps its own row instead of becoming a card that holds
+ // nothing but a table.
+ const tableJoinsTextGroup = (index: number): boolean =>
+ nodes[index].type === 'table' && !!currentTextGroup && !nodes[index].startsGroup
+
nodes.forEach((node, index) => {
const shouldBreakTextGroupForInsertMenu = node.id === insertMenuNodeId && !isPromptComponentNode(node)
- if ((isTextGroupNode(node) || commentJoinsTextGroup(index)) && !shouldBreakTextGroupForInsertMenu) {
+ if (
+ (isTextGroupNode(node) || commentJoinsTextGroup(index) || tableJoinsTextGroup(index)) &&
+ !shouldBreakTextGroupForInsertMenu
+ ) {
if (node.startsGroup) {
currentTextGroup = null
}