@
reorx 我翻了一下代码,我当时是这样实现的:
```javascript
this.registerEvent(
this.app.workspace.on('editor-change', (editor: Editor, markdownView: MarkdownView) => {
const pos = editor.getCursor();
const line = editor.getLine(pos.line);
if (line.trim().startsWith("![[Pasted image")) {
const orig = line.trim().replace("![[", "").replace("]]", "").split("|").first();
const new_name = RenameImage.renameImage(orig);
RenameImage.replaceFirstOccurrence(editor, orig, new_name);
}
}
)
);
this.registerEvent(
this.app.vault.on('create', (file) => {
if (file.name.startsWith("Pasted image")) {
console.log("Paste Image:", file);
console.log("parent: ", file.parent);
const new_name = RenameImage.renameImage(
file.name);
this.app.vault.rename(file, file.parent.path + "/" + new_name);
}
})
)
```
我当时想吧 'Paste image xxxxx.jpg' 改成 'paste_image_xxxx.jpg'
因为空格有时候会导致问题。
但是后来我不太用这个功能了,因为我用一些小脚本处理发布相关的逻辑:
https://catcoding.me/p/publish-to-wechat/