Fix attachment scanning for literal text and multiline links
This commit is contained in:
1 parent
c08bb8a182
commit
b4054189cf
7 files changed
+463
-222
No files matched your search
@@ -53,6 +53,29 @@ func TestImageMoveUpdatesLocalReferences(t *testing.T) {
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func TestImageMovePreservesMultilineMarkdownAndIgnoresLiteralPaths(t *testing.T) {
|
||||
v := newVault(t)
|
||||
if err := os.WriteFile(filepath.Join(v.Root(), "old.png"), []byte("image"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
content := "> ![图片][pic]\r\n>\r\n> [pic]: old.png \"[示例](old.png)\"\r\n\n\n\n普通文字 ](old.png)\n\n[^1]: old.png\n\n``\n\n> ```md\n> \n> ```\n"
|
||||
if _, err := v.Write("文章.md", []byte(content), Precondition{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := v.Move("old.png", "new.png", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, _, err := v.Read("文章.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := strings.Replace(content, "[pic]: old.png", "[pic]: new.png", 1)
|
||||
want = strings.Replace(want, "
|
||||
if string(body) != want {
|
||||
t.Fatalf("应只改写真正的图片引用:\n%s\n期望:\n%s", body, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceImagePreservesPathAndUploadContents(t *testing.T) {
|
||||
v := newVault(t)
|
||||
link, err := v.SaveAsset("a.md", "old.png", strings.NewReader("original"), 100)
|
||||
|
||||
Reference in new issue
Block a user