Skip to content

Commit a239235

Browse files
committed
Unify markdown to a single renderer.
1 parent 05e6cca commit a239235

9 files changed

Lines changed: 171 additions & 642 deletions

File tree

core/App.css

Lines changed: 66 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,141 +1623,53 @@ html[data-codiff-platform='darwin'] .sidebar {
16231623

16241624
.codiff-markdown-preview:not(.editable) {
16251625
color: var(--text);
1626-
font: 14px/1.55 var(--font-sans);
1627-
overflow-wrap: anywhere;
1628-
padding: 18px 24px 26px;
16291626
white-space: normal;
1630-
word-break: normal;
1631-
}
1632-
1633-
.codiff-markdown-preview:not(.editable) > :first-child {
1634-
margin-top: 0;
1635-
}
1636-
1637-
.codiff-markdown-preview:not(.editable) > :last-child {
1638-
margin-bottom: 0;
1639-
}
1640-
1641-
.codiff-markdown-preview:not(.editable) h1,
1642-
.codiff-markdown-preview:not(.editable) h2,
1643-
.codiff-markdown-preview:not(.editable) h3,
1644-
.codiff-markdown-preview:not(.editable) h4,
1645-
.codiff-markdown-preview:not(.editable) h5,
1646-
.codiff-markdown-preview:not(.editable) h6 {
1647-
color: var(--text);
1648-
font-weight: 700;
1649-
line-height: 1.2;
1650-
margin: 22px 0 10px;
1651-
}
1652-
1653-
.codiff-markdown-preview:not(.editable) h1 {
1654-
border-bottom: 1px solid var(--file-border);
1655-
font-size: 24px;
1656-
padding-bottom: 8px;
16571627
}
16581628

1659-
.codiff-markdown-preview:not(.editable) h2 {
1660-
border-bottom: 1px solid var(--file-border);
1661-
font-size: 20px;
1662-
padding-bottom: 6px;
1663-
}
1664-
1665-
.codiff-markdown-preview:not(.editable) h3 {
1666-
font-size: 17px;
1667-
}
1668-
1669-
.codiff-markdown-preview:not(.editable) p,
1670-
.codiff-markdown-preview:not(.editable) blockquote,
1671-
.codiff-markdown-preview:not(.editable) ol,
1672-
.codiff-markdown-preview:not(.editable) ul,
1673-
.codiff-markdown-preview:not(.editable) pre {
1674-
margin: 0 0 14px;
1675-
}
1676-
1677-
.codiff-markdown-preview:not(.editable) .codiff-markdown-added {
1678-
border-radius: 0 6px 6px 0;
1679-
position: relative;
1629+
.codiff-markdown-preview-editor {
1630+
--codiff-readonly-markdown-accent: var(--tree-selection-focus);
1631+
--mdx-editor-accent: var(--codiff-readonly-markdown-accent);
1632+
--mdx-editor-accent-contrast: #fff;
1633+
--mdx-editor-accent-soft: var(--tree-selection-bg);
1634+
--mdx-editor-bg: transparent;
1635+
--mdx-editor-border: transparent;
1636+
--mdx-editor-code-bg: var(--inline-code-bg);
1637+
--mdx-editor-font: var(--font-sans);
1638+
--mdx-editor-font-size: 14px;
1639+
--mdx-editor-hover: var(--hover-wash);
1640+
--mdx-editor-line-height: 1.55;
1641+
--mdx-editor-mono-font: var(--font-mono);
1642+
--mdx-editor-muted: var(--muted);
1643+
--mdx-editor-padding: 18px 24px 26px;
1644+
--mdx-editor-selection: var(--tree-selection-bg);
1645+
--mdx-editor-text: var(--text);
1646+
display: block;
16801647
}
16811648

1682-
.codiff-markdown-preview:not(.editable) .codiff-markdown-added::before {
1683-
background: var(--diff-addition);
1649+
.codiff-markdown-preview-editor .mdx-editor-content {
1650+
border: 0;
16841651
border-radius: 0;
1685-
bottom: 0;
1686-
content: '';
1687-
left: 0;
1688-
position: absolute;
1689-
top: 0;
1690-
width: 3px;
1691-
}
1692-
1693-
.codiff-markdown-preview:not(.editable)
1694-
:is(h1, h2, h3, h4, h5, h6, p, blockquote, pre).codiff-markdown-added {
1695-
margin-inline: -10px;
1696-
padding: 6px 10px 6px 14px;
16971652
}
16981653

1699-
.codiff-markdown-preview:not(.editable) ol,
1700-
.codiff-markdown-preview:not(.editable) ul {
1701-
padding-left: 22px;
1702-
}
1703-
1704-
.codiff-markdown-preview:not(.editable) :is(ol, ul).codiff-markdown-added {
1705-
margin-inline: -10px;
1706-
padding: 6px 10px 6px 34px;
1654+
.codiff-markdown-preview-editor .mdx-editor-content a,
1655+
.review-comment-codex-reply-markdown .mdx-editor-content a {
1656+
color: var(--codiff-readonly-markdown-accent);
1657+
text-decoration: none;
17071658
}
17081659

1709-
.codiff-markdown-preview:not(.editable) li + li {
1710-
margin-top: 4px;
1660+
.codiff-markdown-preview-editor .mdx-editor-content a:hover,
1661+
.review-comment-codex-reply-markdown .mdx-editor-content a:hover {
1662+
text-decoration: underline;
1663+
text-decoration-color: currentColor;
17111664
}
17121665

1713-
.codiff-markdown-preview:not(.editable) blockquote {
1714-
border-left: 3px solid var(--file-border);
1666+
.codiff-readonly-markdown-loading {
1667+
align-items: center;
17151668
color: var(--muted);
1716-
padding-left: 12px;
1717-
}
1718-
1719-
.codiff-markdown-preview:not(.editable) pre {
1720-
background: rgb(127 127 127 / 0.09);
1721-
border: 1px solid rgb(127 127 127 / 0.14);
1722-
border-radius: 8px;
1723-
corner-shape: squircle;
1724-
font: 13px/1.45 var(--font-mono);
1725-
overflow-x: hidden;
1726-
padding: 12px;
1727-
white-space: pre-wrap;
1728-
word-break: break-word;
1729-
}
1730-
1731-
.codiff-markdown-code-block {
1732-
background: rgb(127 127 127 / 0.09);
1733-
border-radius: 8px;
1734-
box-shadow: none;
1735-
corner-shape: squircle;
1736-
display: block;
1737-
margin: 0 0 14px;
1738-
max-inline-size: 100%;
1739-
min-inline-size: 0;
1740-
overflow: clip;
1741-
}
1742-
1743-
.codiff-markdown-preview:not(.editable) .codiff-markdown-code-added {
1744-
margin-inline: -10px;
1745-
padding-inline: 10px;
1746-
}
1747-
1748-
.codiff-markdown-preview:not(.editable) code {
1749-
font-family: var(--font-mono);
1750-
}
1751-
1752-
.codiff-markdown-preview:not(.editable) hr {
1753-
border: 0;
1754-
border-top: 1px solid var(--file-border);
1755-
margin: 20px 0;
1756-
}
1757-
1758-
.codiff-markdown-preview:not(.editable) hr.codiff-markdown-added {
1759-
margin-inline: -10px;
1760-
padding: 6px 10px;
1669+
display: flex;
1670+
font: 13px/1.4 var(--font-sans);
1671+
min-height: 180px;
1672+
padding: 24px;
17611673
}
17621674

17631675
.codiff-markdown-document-editor,
@@ -2688,6 +2600,38 @@ html[data-codiff-platform='darwin'] .sidebar {
26882600
color: var(--danger);
26892601
}
26902602

2603+
.review-comment-codex-reply-markdown {
2604+
--codiff-readonly-markdown-accent: var(--tree-selection-focus);
2605+
--mdx-editor-accent: var(--codiff-readonly-markdown-accent);
2606+
--mdx-editor-accent-contrast: #fff;
2607+
--mdx-editor-accent-soft: var(--tree-selection-bg);
2608+
--mdx-editor-bg: transparent;
2609+
--mdx-editor-border: transparent;
2610+
--mdx-editor-code-bg: var(--inline-code-bg);
2611+
--mdx-editor-font: var(--font-sans);
2612+
--mdx-editor-font-size: 13px;
2613+
--mdx-editor-hover: var(--hover-wash);
2614+
--mdx-editor-line-height: 1.5;
2615+
--mdx-editor-mono-font: var(--font-mono);
2616+
--mdx-editor-muted: var(--muted);
2617+
--mdx-editor-padding: 0;
2618+
--mdx-editor-selection: var(--tree-selection-bg);
2619+
--mdx-editor-text: var(--text);
2620+
display: block;
2621+
}
2622+
2623+
.review-comment-codex-reply-markdown.codiff-readonly-markdown-loading {
2624+
min-height: 76px;
2625+
padding: 0;
2626+
place-content: center;
2627+
}
2628+
2629+
.review-comment-codex-reply-markdown .mdx-editor-content {
2630+
border: 0;
2631+
border-radius: 0;
2632+
min-height: 0;
2633+
}
2634+
26912635
.review-comment-codex-reply p,
26922636
.review-comment-codex-reply ul,
26932637
.review-comment-codex-reply pre {

core/__tests__/App-render.test.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ const renderAppForOpenFileShortcut = async (file: ChangedFile) => {
245245

246246
await waitFor(() => {
247247
expect(container.querySelector('.loading')).toBeNull();
248-
expect(container.querySelector('.codiff-file-header.selected')).not.toBeNull();
248+
expect(container.querySelector('.codiff-file-header')).not.toBeNull();
249249
});
250250

251251
return {
@@ -433,9 +433,11 @@ test('repository reload restores the selected file when it still exists', async
433433
} satisfies RepositoryState;
434434

435435
writeReloadSelection(nextState, secondFile.path);
436+
const openFile = vi.fn(async () => {});
436437

437438
window.codiff = createCodiffMock({
438439
getRepositoryState: vi.fn(async () => nextState),
440+
openFile,
439441
});
440442

441443
const container = document.createElement('div');
@@ -450,10 +452,13 @@ test('repository reload restores the selected file when it still exists', async
450452

451453
await waitFor(() => {
452454
expect(container.querySelector('.loading')).toBeNull();
453-
expect(
454-
container.querySelector('.codiff-file-header.selected .codiff-file-path')?.textContent,
455-
).toBe(secondFile.path);
455+
expect(container.querySelector('.codiff-file-header')).not.toBeNull();
456+
});
457+
await act(async () => {
458+
dispatchModK();
459+
await new Promise((resolve) => setTimeout(resolve, 0));
456460
});
461+
expect(openFile).toHaveBeenCalledWith(secondFile.path);
457462
} finally {
458463
if (root) {
459464
await act(async () => root?.unmount());
@@ -477,9 +482,11 @@ test('repository reload restores the selected file from the previous source', as
477482
);
478483

479484
writeReloadSelection(nextState, secondFile.path);
485+
const openFile = vi.fn(async () => {});
480486

481487
window.codiff = createCodiffMock({
482488
getRepositoryState,
489+
openFile,
483490
});
484491

485492
const container = document.createElement('div');
@@ -494,10 +501,13 @@ test('repository reload restores the selected file from the previous source', as
494501

495502
await waitFor(() => {
496503
expect(container.querySelector('.loading')).toBeNull();
497-
expect(
498-
container.querySelector('.codiff-file-header.selected .codiff-file-path')?.textContent,
499-
).toBe(secondFile.path);
504+
expect(container.querySelector('.codiff-file-header')).not.toBeNull();
505+
});
506+
await act(async () => {
507+
dispatchModK();
508+
await new Promise((resolve) => setTimeout(resolve, 0));
500509
});
510+
expect(openFile).toHaveBeenCalledWith(secondFile.path);
501511
expect(getRepositoryState).toHaveBeenCalledWith(source);
502512
} finally {
503513
if (root) {

core/__tests__/App.test.tsx

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { renderToStaticMarkup } from 'react-dom/server';
21
import { expect, test } from 'vite-plus/test';
32
import { getDiffSearchResult } from '../lib/diff-search.ts';
43
import {
@@ -11,7 +10,6 @@ import {
1110
shouldLoadDiffSectionContents,
1211
} from '../lib/diff.ts';
1312
import { isDiffSearchShortcut } from '../lib/keyboard.ts';
14-
import { renderMarkdown } from '../lib/markdown.tsx';
1513
import {
1614
buildReviewCommentsMarkdown,
1715
shouldDiscardReviewCommentOnEscape,
@@ -373,7 +371,7 @@ test('total diff line counts sum countable files only', () => {
373371
});
374372
});
375373

376-
test('markdown previews track added source lines for modified files', () => {
374+
test('markdown previews use new file contents for modified files', () => {
377375
const file = {
378376
fingerprint: 'markdown-preview-added-lines',
379377
path: 'README.md',
@@ -401,71 +399,6 @@ test('markdown previews track added source lines for modified files', () => {
401399
const preview = getMarkdownPreviewContents(file, section, fileDiff);
402400

403401
expect(preview?.contents).toBe(file.sections[0].newFile?.contents);
404-
expect([...(preview?.addedLines ?? [])]).toEqual([2, 3, 5]);
405-
});
406-
407-
test('markdown previews do not mark every line for new files', () => {
408-
const file = {
409-
fingerprint: 'markdown-preview-new-file',
410-
path: 'README.md',
411-
sections: [
412-
{
413-
binary: false,
414-
id: 'README.md:staged',
415-
kind: 'staged',
416-
loadState: 'ready',
417-
newFile: {
418-
contents: '# Title\nAll new.\n',
419-
name: 'README.md',
420-
},
421-
oldFile: {
422-
contents: '',
423-
name: 'README.md',
424-
},
425-
patch: '',
426-
},
427-
],
428-
status: 'added',
429-
} satisfies ChangedFile;
430-
const [{ fileDiff, section }] = getVisibleDiffSections(file, false);
431-
432-
const preview = getMarkdownPreviewContents(file, section, fileDiff);
433-
434-
expect(preview?.addedLines.size).toBe(0);
435-
});
436-
437-
test('rendered markdown marks blocks intersecting added source lines', () => {
438-
const html = renderToStaticMarkup(
439-
<>
440-
{renderMarkdown(
441-
[
442-
'# Title',
443-
'',
444-
'paragraph line one',
445-
'paragraph line two',
446-
'',
447-
'- kept',
448-
'- added',
449-
'',
450-
'> quoted',
451-
'',
452-
'---',
453-
'',
454-
'```ts',
455-
'const value = true;',
456-
'```',
457-
].join('\n'),
458-
{ addedLines: new Set([4, 7, 9, 11, 14]) },
459-
)}
460-
</>,
461-
);
462-
463-
expect(html.match(/codiff-markdown-added/g)).toHaveLength(5);
464-
expect(html).toContain('<p class="codiff-markdown-added">');
465-
expect(html).toContain('<ul class="codiff-markdown-added">');
466-
expect(html).toContain('<blockquote class="codiff-markdown-added">');
467-
expect(html).toContain('<hr class="codiff-markdown-added"/>');
468-
expect(html).toContain('<div class="codiff-markdown-code-added codiff-markdown-added"><pre>');
469402
});
470403

471404
test('diff search shortcut does not claim fullscreen shortcut', () => {

0 commit comments

Comments
 (0)