Skip to content
Merged
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
13 changes: 8 additions & 5 deletions internal/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -3051,12 +3051,15 @@ func cleanAssetFilename(name string) (string, error) {
}

// makeAssetMarkdown mirrors the desktop markdownForImportedAsset: everything is
// linked by VAULT-relative path, an image as a wikilink and anything else as a
// markdown link, which is the single form every client now writes. The link
// used to be relative to the note, so it broke as soon as the note moved to
// another depth (nothing rewrites relative asset paths on move).
// linked by VAULT-relative path, an image, PDF, audio or video file as an embed
// the note shows in place (a picture, a document, a player) and anything else
// as a markdown link, which is the single form every client now writes. The
// link used to be relative to the note, so it broke as soon as the note moved
// to another depth (nothing rewrites relative asset paths on move), and media
// used to be a bare link, so an attached video showed only its file name.
func makeAssetMarkdown(vaultRelPath, kind, name string) string {
if kind == "image" {
switch kind {
case "image", "pdf", "audio", "video":
return "![[" + vaultRelPath + "]]"
}
dest := "<" + strings.ReplaceAll(vaultRelPath, ">", "%3E") + ">"
Expand Down
24 changes: 24 additions & 0 deletions internal/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ func TestImportAssetEmbedsImagesByVaultRelativeWikilink(t *testing.T) {
}
}

// Media embeds so the note shows a player or the document in place, the same
// rule the desktop and both phones follow; any other file stays a link.
func TestImportAssetEmbedsMediaAndLinksOtherFiles(t *testing.T) {
root := t.TempDir()
v, err := New(root, Options{})
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct{ name, kind, markdown string }{
{"Clip.mov", "video", "![[assets/Clip.mov]]"},
{"Talk.mp3", "audio", "![[assets/Talk.mp3]]"},
{"Year end.pdf", "pdf", "![[assets/Year end.pdf]]"},
{"Archive.zip", "file", "[Archive.zip](<assets/Archive.zip>)"},
} {
asset, err := v.ImportAsset("Note.md", tc.name, bytes.NewReader([]byte{1, 2, 3}))
if err != nil {
t.Fatalf("%s: %v", tc.name, err)
}
if asset.Kind != tc.kind || asset.Markdown != tc.markdown {
t.Fatalf("%s: kind %q markdown %q, want %q %q", tc.name, asset.Kind, asset.Markdown, tc.kind, tc.markdown)
}
}
}

func TestImportAssetScrubsNamesThatBreakWikilinks(t *testing.T) {
root := t.TempDir()
v, err := New(root, Options{})
Expand Down
Loading