diff --git a/src/renderer/src/components/editor/EditorContent.markdown-classification.test.tsx b/src/renderer/src/components/editor/EditorContent.markdown-classification.test.tsx index a6fc8b415f7..2a75f4a0a78 100644 --- a/src/renderer/src/components/editor/EditorContent.markdown-classification.test.tsx +++ b/src/renderer/src/components/editor/EditorContent.markdown-classification.test.tsx @@ -95,6 +95,7 @@ function openFile( function renderEditPath({ content, + savedContent = '# Saved', language = 'markdown', viewMode = 'rich', mode = 'edit', @@ -102,6 +103,7 @@ function renderEditPath({ onOpenMarkdownPreview }: { content: string + savedContent?: string language?: 'markdown' | 'typescript' viewMode?: 'source' | 'rich' | 'preview' mode?: 'edit' | 'markdown-preview' @@ -110,7 +112,7 @@ function renderEditPath({ }) { const activeFile = openFile(language, mode) const fileContents = { - [activeFile.id]: { content: '# Saved', isBinary: false } + [activeFile.id]: { content: savedContent, isBinary: false } } const editorDrafts = { [activeFile.id]: content } const model = getEditorPanelRenderModel({ @@ -310,7 +312,10 @@ describe('inline Markdown render classification', () => { }) it('offers the Preview toggle once rich mode falls back to source for this content', () => { - const fallback = renderEditPath({ content: '[reference]: https://example.com' }) + const fallback = renderEditPath({ + content: '[reference]: https://example.com', + savedContent: '[reference]: https://example.com' + }) expect(fallback.model.availableEditorToggleModes).toEqual([ 'source', 'rich', @@ -326,6 +331,7 @@ describe('inline Markdown render classification', () => { const content = '[reference]: https://example.com' const result = renderEditPath({ content, + savedContent: content, viewMode: 'source', markdownRichModeFaultedContent: { [openFile().id]: content } }) diff --git a/src/renderer/src/components/editor/markdown-round-trip.test.ts b/src/renderer/src/components/editor/markdown-round-trip.test.ts index d8646283790..772e1a4a2e8 100644 --- a/src/renderer/src/components/editor/markdown-round-trip.test.ts +++ b/src/renderer/src/components/editor/markdown-round-trip.test.ts @@ -841,3 +841,17 @@ it('preserves code spacing inside a table across repeated saves', () => { expect(once).toContain('`a b`') expect(roundTripMarkdown(once)).toBe(once) }) + +it('retains an unchanged raw destination while repairing nearby attributes', () => { + const source = '[a](b\\)c) and ![x](image.png "say \\"hi\\"")' + expect(roundTripMarkdown(source)).toBe(source) +}) + +it('encodes spaces in edited destinations', () => { + expect(markdownAfterDestinationEdit('[a](old)', 'link', 'docs/My File.md')).toBe( + '[a](docs/My%20File.md)' + ) + expect(markdownAfterDestinationEdit('![a](old.png)', 'image', 'My Image.png')).toBe( + '![a](My%20Image.png)' + ) +})