Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/desktop/src/renderer/export-window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
resolveCustomThemeMode
} from '@renderer/lib/custom-themes'
import { withExportTitle } from '@shared/export-title'
import { rewriteWikilinkImageEmbeds } from '@shared/embed-size'
import '@renderer/styles/index.css'

const PREFS_KEY = 'zen:prefs:v2'
Expand Down Expand Up @@ -446,7 +447,9 @@ function ExportNoteWindow({ notePath }: { notePath: string }): JSX.Element {
`}</style>
<main className="export-note-shell">
<Preview
markdown={withExportTitle(note.body, note.title).markdown}
markdown={rewriteWikilinkImageEmbeds(
withExportTitle(note.body, note.title).markdown
)}
notePath={note.path}
onRendered={() => setExportState('ready')}
/>
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/export-window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client'
import type { AssetMeta, NoteContent, NoteMeta, VaultInfo } from '@shared/ipc'
import { LazyPreview as Preview } from '@renderer/components/LazyPreview'
import { useStore } from '@renderer/store'
import { rewriteWikilinkImageEmbeds } from '@shared/embed-size'
import '@renderer/styles/index.css'

const PREFS_KEY = 'zen:prefs:v2'
Expand Down Expand Up @@ -244,7 +245,11 @@ function ExportNoteWindow({ notePath }: { notePath: string }): JSX.Element {
}
`}</style>
<main className="export-note-shell">
<Preview markdown={note.body} notePath={note.path} onRendered={() => void triggerPrint()} />
<Preview
markdown={rewriteWikilinkImageEmbeds(note.body)}
notePath={note.path}
onRendered={() => void triggerPrint()}
/>
</main>
</>
)
Expand Down
14 changes: 14 additions & 0 deletions packages/app-core/src/lib/local-assets-vault-root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe('#459 — vault-root wikilink embeds resolve from the root', () => {
const img = root.querySelector<HTMLImageElement>('img')!
expect(img.dataset.localAssetUrl).toBe('zen-asset://v/assets/image.png')
})

it('leaves a missing image unresolved without throwing', async () => {
const { useStore, enhanceLocalAssetNodes } = await load()
useStore.setState({ assetFiles: [{ path: 'assets/other.png' }] as never })
const root = document.createElement('div')
root.innerHTML = '<p><img src="missing image.png" alt="Missing image"></p>'

expect(() =>
enhanceLocalAssetNodes(root, { vaultRoot: '/v', notePath: DAILY_NOTE })
).not.toThrow()
const img = root.querySelector<HTMLImageElement>('img')!
expect(img.dataset.localAssetUrl).toBe('zen-asset://v/missing image.png')
expect(img.getAttribute('alt')).toBe('Missing image')
})
})

// #462: imported Obsidian vaults use per-folder `attachments/` directories and
Expand Down
8 changes: 8 additions & 0 deletions packages/shared-domain/src/embed-size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ describe('rewriteWikilinkImageEmbeds', () => {
expect(rewriteWikilinkImageEmbeds('![[chart.png|Quarter|600x400]]')).toBe('![Quarter|600x400](chart.png)')
expect(rewriteWikilinkImageEmbeds('![[assets/my chart.png]]')).toBe('![](<assets/my chart.png>)')
})
it('supports nested paths, spaces, alt text, and dimension labels used by PDF export', () => {
expect(rewriteWikilinkImageEmbeds('![[subfolder/team photo.png|Team photo]]')).toBe(
'![Team photo](<subfolder/team photo.png>)'
)
expect(rewriteWikilinkImageEmbeds('![[subfolder/team photo.png|300]]')).toBe(
'![|300](<subfolder/team photo.png>)'
)
})
it('leaves note embeds and fenced code alone', () => {
const doc = '![[Some note]]\n\n```md\n![[chart.png]]\n```\n\n![[chart.png]]'
expect(rewriteWikilinkImageEmbeds(doc)).toBe('![[Some note]]\n\n```md\n![[chart.png]]\n```\n\n![](chart.png)')
Expand Down