Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): align source-view tables with surrounding text (PRD-6922) (#1603)
Andrew Mikofalvy178a57c91164
diff --git a/.changeset/fix-source-table-indent.md b/.changeset/fix-source-table-indent.mdnew file mode 100644index 000000000..1681dea02--- /dev/null+++ b/.changeset/fix-source-table-indent.md@@ -0,0 +1,14 @@+---+"@inkeep/open-knowledge": patch+---++fix(open-knowledge): source-view tables no longer render indented left of surrounding text++GFM table rows in the Markdown source view rendered roughly 2ch to the left of the+surrounding prose, headings, and lists. The source-polish view-plugin set the+`.cm-table-row` / `.cm-table-header` line classes but never set the `--list-hang`+variable that the base `.cm-line` rule consumes, so the base `!important`+`padding-inline-start` overrode the standalone table `padding` while the table's+negative `text-indent` still applied, pulling table lines into the gutter. Tables+now participate in the same hanging-indent mechanism as lists and fenced code, so+they line up with body text. (PRD-6922)diff --git a/packages/app/src/editor/source-polish/view-plugin.test.ts b/packages/app/src/editor/source-polish/view-plugin.test.tsindex 62aa4d00c..964ee4b7c 100644--- a/packages/app/src/editor/source-polish/view-plugin.test.ts+++ b/packages/app/src/editor/source-polish/view-plugin.test.ts@@ -15,6 +15,7 @@ interface DecoInfo {from: number;to: number;classes: string;+ style: string;isLine: boolean;}@@ -25,12 +26,17 @@ function collect(doc: string): DecoInfo[] {const cursor = set.iter();while (cursor.value) {const spec =- (cursor.value as unknown as { spec?: { class?: string; attributes?: unknown } }).spec ?? {};+ (+ cursor.value as unknown as {+ spec?: { class?: string; attributes?: { style?: string } };+ }+ ).spec ?? {};const isLine = cursor.from === cursor.to;out.push({from: cursor.from,to: cursor.to,classes: (spec.class ?? '') as string,+ style: spec.attributes?.style ?? '',isLine,});cursor.next();@@ -42,6 +48,10 @@ function classesAtLine(decos: DecoInfo[], lineFrom: number): string[] {return decos.filter((d) => d.isLine && d.from === lineFrom).map((d) => d.classes);}+function styleAtLine(decos: DecoInfo[], lineFrom: number): string[] {+ return decos.filter((d) => d.isLine && d.from === lineFrom).map((d) => d.style);+}+function markRangesWithClass(decos: DecoInfo[], cls: string): Array<{ from: number; to: number }> {return decos.filter((d) => !d.isLine && d.classes.split(/\s+/).includes(cls))@@ -149,6 +159,14 @@ describe('source-polish view-plugin — buildDecorationsForRanges', () => {expect(classesAtLine(decos, 20).join(' ')).toContain('cm-table-row');});+ test('table lines carry --list-hang: 2ch so the hang composes through the .cm-line calc (like lists)', () => {+ const doc = '| a | b |\n| - | - |\n| 1 | 2 |';+ const decos = collect(doc);+ expect(styleAtLine(decos, 0).join(' ')).toContain('--list-hang: 2ch');+ expect(styleAtLine(decos, 10).join(' ')).toContain('--list-hang: 2ch');+ expect(styleAtLine(decos, 20).join(' ')).toContain('--list-hang: 2ch');+ });+test('each table line gets exactly ONE of {cm-table-header, cm-table-row} — no duplicate from TableDelimiter nested in TableRow', () => {const doc = '| alpha | beta |\n| - | - |\n| one | two |';const decos = collect(doc);diff --git a/packages/app/src/editor/source-polish/view-plugin.ts b/packages/app/src/editor/source-polish/view-plugin.tsindex 25f31be17..445e2a421 100644--- a/packages/app/src/editor/source-polish/view-plugin.ts+++ b/packages/app/src/editor/source-polish/view-plugin.ts@@ -12,8 +12,14 @@ const LIST_PREFIX_RE = /^(\s*(?:[-*+]|\d+[.)]) (?:\[[ x]\] )?)/;const delMark = Decoration.mark({ class: 'cm-del' });-const tableHeaderLine = Decoration.line({ class: 'cm-table-header' });-const tableRowLine = Decoration.line({ class: 'cm-table-row' });+const tableHeaderLine = Decoration.line({+ class: 'cm-table-header',+ attributes: { style: '--list-hang: 2ch' },+});+const tableRowLine = Decoration.line({+ class: 'cm-table-row',+ attributes: { style: '--list-hang: 2ch' },+});function countLeadingIndent(text: string): number {let indent = 0;diff --git a/packages/app/src/globals.css b/packages/app/src/globals.cssindex 2d2a246e1..21f6b4efe 100644--- a/packages/app/src/globals.css+++ b/packages/app/src/globals.css@@ -4581,15 +4581,21 @@ html.electron-mode [data-slot="sidebar-inner"] {--broken-link-color: oklch(72% 0.18 25);}-/* Tables — hanging indent only. Wrapped row continuation aligns under the- first cell's content, not under `|`. No background, no border, no accent- bar, no cell bands, NO font-size change — table lines read as the same- size as surrounding paragraph text. Compactness was cut as stylistic- (see SPEC §6.6, §11 D4). */+/* Tables — hanging indent only, composed through .cm-line's additive-calc+ via --list-hang (set inline by the source-polish view-plugin on+ table-row/header lines — same mechanism lists use). Wrapped row+ continuation aligns under the first cell's content, not under `|`. No+ background, no border, no accent bar, no cell bands, NO font-size change —+ table lines read as the same size as surrounding paragraph text. Like+ .cm-list-item, redundant while .cm-line carries !important on+ padding-inline-start and incorporates --list-hang; retained as+ documentation. The prior standalone calc(8px + 2ch) was overridden by the+ base !important while the negative text-indent leaked, pulling tables ~2ch+ left of prose. */.cm-table-row,.cm-table-header {- padding-inline-start: calc(8px + 2ch);- text-indent: -2ch;+ padding-inline-start: var(--list-hang, 2ch);+ text-indent: calc(-1 * var(--list-hang, 2ch));}/* V2 mode-toggle visibility (FR9, V2 SPEC §8b) — replaces Tailwind'sdiff --git a/packages/app/tests/stress/cm6-list-hanging-indent.e2e.ts b/packages/app/tests/stress/cm6-list-hanging-indent.e2e.tsindex e648636f8..385dc3f37 100644--- a/packages/app/tests/stress/cm6-list-hanging-indent.e2e.ts+++ b/packages/app/tests/stress/cm6-list-hanging-indent.e2e.ts@@ -252,4 +252,101 @@ test.describe('CM6 source-mode padding contract', () => {(violations.length > 0 ? `\n\nViolations:\n${violations.join('\n')}` : ''),).toEqual([]);});++ test('table lines align with prose (not pulled left of the baseline)', async ({ page, api }) => {+ const docName = `cm6-table-${randomUUID().slice(0, 8)}`;+ await api.createPage(`${docName}.md`);+ await page.goto(`/#/${docName}`);+ await waitForProvider(page);+ await page.waitForSelector('.ProseMirror');++ const tableFixture = [+ 'Baseline prose paragraph for alignment.',+ '',+ '| Species | Count |',+ '| --- | --- |',+ '| Flounder | 4 |',+ '',+ ].join('\n');+ await seedMarkdown(api, docName, tableFixture);++ await page.getByRole('radio', { name: 'Markdown source' }).click();+ await page.waitForSelector('.cm-content', { timeout: 10_000 });+ await page.waitForFunction(+ () =>+ document.querySelectorAll('.cm-line.cm-table-header').length >= 1 &&+ document.querySelectorAll('.cm-line.cm-table-row').length >= 2,+ null,+ { timeout: 10_000 },+ );++ const measured = await page.evaluate(() => {+ function firstGlyphLeft(line: HTMLElement): number {+ const lineLeft = line.getBoundingClientRect().left;+ const walker = document.createTreeWalker(line, NodeFilter.SHOW_TEXT);+ let node = walker.nextNode() as Text | null;+ while (node && (!node.nodeValue || node.nodeValue.length === 0)) {+ node = walker.nextNode() as Text | null;+ }+ if (!node?.nodeValue) return lineLeft;+ const range = document.createRange();+ range.setStart(node, 0);+ range.setEnd(node, 1);+ return range.getBoundingClientRect().left;+ }+ function measureLine(line: HTMLElement) {+ const cs = getComputedStyle(line);+ return {+ text: (line.textContent ?? '').slice(0, 40),+ firstGlyphLeft: firstGlyphLeft(line),+ lineLeft: line.getBoundingClientRect().left,+ paddingLeftPx: parseFloat(cs.paddingLeft) || 0,+ textIndentPx: parseFloat(cs.textIndent) || 0,+ };+ }+ const allLines = Array.from(document.querySelectorAll<HTMLElement>('.cm-content .cm-line'));+ const proseEl = allLines.find(+ (l) =>+ (l.textContent ?? '').includes('Baseline prose') &&+ !l.classList.contains('cm-table-row') &&+ !l.classList.contains('cm-table-header') &&+ !l.classList.contains('cm-list-item') &&+ !l.classList.contains('cm-fenced-code-line'),+ );+ const tableLines = Array.from(+ document.querySelectorAll<HTMLElement>('.cm-line.cm-table-header, .cm-line.cm-table-row'),+ );+ return {+ prose: proseEl ? measureLine(proseEl) : null,+ tableLines: tableLines.map(measureLine),+ };+ });++ const prose = measured.prose;+ if (!prose) throw new Error('expected a plain prose .cm-line baseline but found none');++ expect(+ measured.tableLines.length,+ 'expected 3 table lines (header + delimiter + 1 data row)',+ ).toBe(3);++ const violations = measured.tableLines+ .filter((t) => Math.abs(t.firstGlyphLeft - prose.firstGlyphLeft) > SUBPIXEL_TOLERANCE_PX)+ .map(+ (t) =>+ ` • "${t.text}": firstGlyph.left=${t.firstGlyphLeft.toFixed(2)}px is ` ++ `${(prose.firstGlyphLeft - t.firstGlyphLeft).toFixed(2)}px off the prose baseline ` ++ `(${prose.firstGlyphLeft.toFixed(2)}px) — padding-left=${t.paddingLeftPx.toFixed(2)}px, ` ++ `text-indent=${t.textIndentPx.toFixed(2)}px → net=${(t.paddingLeftPx + t.textIndentPx).toFixed(2)}px`,+ );++ expect(+ violations,+ `\nTable lines must start at the same x as surrounding prose in source mode. ` ++ `The following are offset from the prose baseline (the bug: --list-hang unset on ` ++ `table lines, so .cm-line's !important padding overrides the standalone .cm-table-row ` ++ `padding while its -2ch text-indent still applies, pulling the table left):\n` ++ violations.join('\n'),+ ).toEqual([]);+ });});