Skip to content

Commit

Permalink
add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxining committed Nov 5, 2023
1 parent 0f2c3fb commit 7db78b3
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 63 deletions.
Empty file modified .editorconfig
100644 → 100755
Empty file.
Empty file modified .eslintignore
100644 → 100755
Empty file.
Empty file modified .eslintrc
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .npmrc
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified esbuild.config.mjs
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions manifest.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "Obsidian-File-Upload-Command",
"name": "File Upload Command",
"id": "Obsidian-Attachment-Upload-Command",
"name": "Attachment Upload",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.",
Expand Down
Empty file modified package-lock.json
100644 → 100755
Empty file.
Empty file modified package.json
100644 → 100755
Empty file.
51 changes: 51 additions & 0 deletions src/attmatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { TAbstractFile } from "obsidian";
import { parse, Uri } from "path";

interface Attachment {
name: string;
path: string;
source: string;
}
export class AttachmentMatch {


getAttachments(markdown: string, filePath: TAbstractFile) {
// 匹配两种语法
const regex = /!\[\[.*\]\]|!\((.*?)(\[\])/g;
const attachments: Attachment[] = [];
const matches = markdown.match(regex);
if (matches) {
matches.forEach((match) => {
// 提取路径
let path = match.slice(3, -2);

// 处理三种形式的路径
if (path.startsWith("../")) {
// 相对路径
path = this.normalizePath(file.parent.path + "/" + path);
} else if (!path.startsWith("/")) {
// 短形式
path = this.normalizePath(file.parent.path + "/" + path);
} else {
// 绝对路径
path = this.normalizePath(path);
}

// 构造Attachment对象
const attachment = {
name: path.split("/").pop(),
path,
source: match,
};

attachments.push(attachment);
});
}

return attachments;
}

// 规范化路径,兼容不同系统
normalizePath(path: string) {
return Uri.parse(path).toString();
}}
Loading

0 comments on commit 7db78b3

Please sign in to comment.