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
150 changes: 37 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,53 @@
# MarkPic

MarkPic 是一个 Windows 桌面工具:把 Markdown 文档里的本地图片上传到 PicGo 图床,并把文档里的图片地址替换成图床链接。它也可以反向处理文章里已有的网络图片:只做检测,或者下载到本地。
[English](README.md) | [简体中文](README.zh-CN.md)

程序是单个 exe,界面内嵌,不需要 Node 或本地服务。数据放在 exe 旁边的 `data` 目录。
MarkPic is a desktop app for the images inside Markdown documents. It does three
independent jobs:

## 功能
- **Upload** — find the local images a document references, send them to your
[PicGo](https://github.com/Molunerfinn/PicGo) image host, and rewrite the links to
the hosted URLs.
- **Check** — walk the remote images an article already points at and report the ones
that are dead, are not images, or come back truncated. Read-only.
- **Download** — pull those remote images into a local `images/` folder and rewrite
the links to relative paths.

- **上传本地图片**:扫描 Markdown / HTML 里的本地图片,经 PicGo 上传,替换成图床地址。
- **检测远程图片**:逐个检查文章里的网络图片,报告打不开、不是图片、只返回半截等状况;只读,不改文档。
- **下载远程图片**:把网络图片下载到文档旁边的 `images/`(目录可改),链接改成相对路径。
- **队列**:拖入文件或文件夹,支持并发、取消、失败重试、只看问题;每张图的明细可以展开。
- **去重与缓存**:同一张图只上传一次;已经上传/下载过且内容未变的图直接复用。
- **三种输出**:sidecar、就地改写(带备份)、输出到指定目录。
- **桌面集成**:亮色/暗色/跟随系统、中文/英文、关闭到托盘、单实例。
It ships as one self-contained app with the UI embedded: no Node.js, no local server,
no command line. Uploads go through PicGo's local HTTP interface, so MarkPic never
sees your image-host credentials.

## 使用
## At a glance

1. 安装并启动 [PicGo](https://github.com/Molunerfinn/PicGo),配置好图床。
2. 在 PicGo 的 **设置 → 设置 Server** 里启用服务(默认 `http://127.0.0.1:36677`)。
3. 打开 MarkPic,把 `.md` 文件或文件夹拖进窗口。
4. 在左侧选择 **上传**、**检测** 或 **下载**,然后开始。

上传只走本机的 PicGo HTTP 接口,MarkPic 不接触图床密钥。检测和下载不上传图片,不需要 PicGo 开着。

### 三种作业

| 作业 | 处理什么 | 会改文档吗 | 需要 PicGo |
| Job | What it touches | Rewrites the document | Needs PicGo running |
| --- | --- | --- | --- |
| 上传 | 本地图片 → 图床 | 会 | 是 |
| 检测 | 检查远程图片是否可用 | 不会 | 否 |
| 下载 | 远程图片 → 本地 `images/` | 会 | 否 |

上传时,文章里原有的远程图片原样保留。检测只读远程地址,但也会指出“文档引用了、磁盘上却不存在”的本地图。下载只处理远程图,本地图保留。

### 输出方式

| 模式 | 结果 |
| --- | --- |
| sidecar(默认) | 生成 `note.converted.md`,原文件不动 |
| in-place | 改写原文件,先备份成 `note.md.bak` |
| directory | 写到指定目录;同名文件自动加序号,不覆盖已有文件 |

## 支持的写法

```markdown
![图片](images/a.png)
![图片](images/a.png "标题")
![图片](<images/带 空格.png>)
![](images/有(括号).png)
<img src="images/a.png" width="60">
<img srcset="images/a.png 1x, images/a@2x.png 2x">
<source srcset="images/wide.png 640w">
![完整][ref1] ![折叠][] ![简写]
[ref1]: images/a.png
```

- 支持引用式图片、HTML `src` / `srcset` / `<source>`、一行多图、带空格或括号的路径。
- 跳过远程图、`data:`、缺失的本地文件,以及 `.ps` / `.eps` / `.pdf` / `.ai` / `.psd` / `.sketch` / `.fig` / `.drawio` 这类附件。
- 代码块、行内代码、HTML 注释、`<pre>` / `<code>` 里的图片不处理。
- 读写 UTF-8(含 BOM)、带 BOM 的 UTF-16 和本机 ANSI 代码页;输出保持原编码。

## 设置

设置面板里可以改:

- PicGo 地址、并发数、重试次数。
- 是否复用上次的上传/下载结果。
- 输出方式、输出目录、sidecar 后缀、远程图存放目录。
- 主题(亮色 / 暗色 / 跟随系统)、语言(中文 / 英文)。
- 关闭窗口时询问、最小化到托盘,还是直接退出;是否开机/启动时进入托盘。

## 数据目录

默认在 exe 旁边:

```text
MarkPic.exe
data/
settings.json
upload-cache.json
remote-cache.json
webview2/
```

如果 exe 所在目录不可写,会退回 `%APPDATA%\markpic`。也可以用环境变量 `MARKPIC_DATA_DIR` 指定别的目录。

## 开发
| Upload | local images → image host | yes | yes |
| Check | remote image URLs | no | no |
| Download | remote images → `images/` | yes | no |

需要 Go 1.24+。构建或修改前端需要 Node 20.19+ 和 pnpm;构建脚本会自动执行 `pnpm --dir web install`。
Documents keep their original encoding — UTF-8 (with or without BOM), UTF-16 with a
BOM, and the machine's ANSI code page. Apart from the rewritten image addresses,
everything comes back byte-for-byte identical.

```bash
npm run build # 构建前端 + bin/MarkPic.exe
npm run build:go # 只编 Go(需要已有 internal/ui/dist)
npm run start # Vite 5173 + 窗口热更新
npm run start:mock # 带假图床,不连 PicGo
npm run test
npm run typecheck
```
## Install

`internal/ui/dist` 不提交到版本库,它是 `go:embed` 的输入。`build`、`start`、`test` 发现产物缺失时会自动构建前端。直接 `go run ./cmd/markpic` 也可以,但同样需要先有 `internal/ui/dist`。
Download `MarkPic-v<version>-windows-amd64.exe` from
[Releases](https://github.com/geekMus/MarkPic/releases). There is no installer: put
it anywhere and run it. An installed copy updates itself; settings and caches live in
the `data/` folder next to the executable.

### 目录结构
Windows is the only platform published so far; macOS and Linux are planned, but not
verified yet.

| 路径 | 内容 |
| --- | --- |
| `cmd/markpic` | 入口、单实例、原生窗口、bridge、标题栏 |
| `internal/app` | bridge 方法表与事件 |
| `internal/mdscan` | Markdown 扫描与按字节替换 |
| `internal/imgpath` | 图片地址分类与解析 |
| `internal/picgo` | PicGo 上传客户端 |
| `internal/conv` | 转换流水线 |
| `internal/remoteimg` | 远程图片检测与下载 |
| `internal/remotecache` | 下载缓存 |
| `internal/uploadcache` | 上传缓存 |
| `internal/settings` | 设置读写 |
| `internal/platform` | 原生对话框 |
| `internal/update` | 更新检查与安装 |
| `internal/ui` | 前端产物(`go:embed`) |
| `web` | Vue 3 + TypeScript + Vite 前端 |
| `scripts` | 构建、启动、测试脚本 |
| `tools/bench` | 基准测试 |
| `tools/mockpicgo` | 假图床 |
## Quick start

图标资源在 `assets/`;常规构建直接使用已提交的 `.ico` 和 `.syso`,不需要重新生成。
1. Install and start [PicGo](https://github.com/Molunerfinn/PicGo), then enable its
server under **Settings → Server** (default `http://127.0.0.1:36677`).
2. Drop `.md` files or a folder onto the MarkPic window.
3. Choose **Upload**, **Check** or **Download** on the left and start.

## 文档
## Documentation

- [Bridge API](docs/API.md)
- [Usage](docs/usage.md) — supported syntax, output modes, settings, data directory
- [Build & development](docs/build.md) — toolchain, scripts, repository layout
- [Bridge API](docs/API.md) — internal WebView2 bridge between the UI and Go
45 changes: 45 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# MarkPic

[English](README.md) | [简体中文](README.zh-CN.md)

MarkPic 是一个桌面工具,处理 Markdown 文档里的图片。三件事互相独立:

- **上传**:找出文档引用的本地图片,交给 [PicGo](https://github.com/Molunerfinn/PicGo)
图床上传,再把文档里的地址换成图床链接。
- **检测**:逐个检查文章里已有的网络图片,报告打不开、不是图片、只返回半截的状况。只读,不改文档。
- **下载**:把这些网络图片下载到本地的 `images/`,链接改成相对路径。

程序是单个自包含的应用,界面内嵌:不需要 Node.js,不起本地服务,没有命令行。上传只走 PicGo
的本机 HTTP 接口,MarkPic 不接触你的图床密钥。

## 一眼看懂

| 作业 | 处理什么 | 会改文档吗 | 需要 PicGo 开着 |
| --- | --- | --- | --- |
| 上传 | 本地图片 → 图床 | 会 | 是 |
| 检测 | 网络图片地址 | 不会 | 否 |
| 下载 | 网络图片 → `images/` | 会 | 否 |

文档保持原编码:UTF-8(含或不含 BOM)、带 BOM 的 UTF-16、以及本机 ANSI 代码页。
除了被替换掉的图片地址,其余内容一个字节都不变。

## 安装

从 [Releases](https://github.com/geekMus/MarkPic/releases) 下载
`MarkPic-v<版本>-windows-amd64.exe`。没有安装程序:放哪都能跑。已安装的版本会自己更新,
设置与缓存放在 exe 旁边的 `data/` 目录里。

目前只发布 Windows 版;macOS 和 Linux 在计划中,但还没有在真机上验证过。

## 快速开始

1. 安装并启动 [PicGo](https://github.com/Molunerfinn/PicGo),在 **设置 → 设置 Server**
里启用服务(默认 `http://127.0.0.1:36677`)。
2. 把 `.md` 文件或文件夹拖进 MarkPic 窗口。
3. 在左侧选 **上传**、**检测** 或 **下载**,然后开始。

## 文档

- [使用说明](docs/usage.zh-CN.md):支持的写法、输出方式、设置、数据目录
- [构建与开发](docs/build.zh-CN.md):工具链、脚本、目录结构
- [Bridge API](docs/API.zh-CN.md):内嵌界面与 Go 之间的通信接口
90 changes: 50 additions & 40 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Bridge API

界面和 Go 进程通过 WebView2 自带的 bridge 通信。这个程序没有 HTTP 服务、命令行或对外接口;下面这套方法只服务于内嵌界面。方法表在 `internal/app/dispatch.go`。
[English](API.md) | [简体中文](API.zh-CN.md) · back to [README](../README.md)

## 调用
The UI and the Go process talk over the bridge that ships with WebView2. There is no
HTTP service, no command line and no public interface — this method table only serves
the embedded UI. It lives in `internal/app/dispatch.go`.

## Calling

```ts
const reply = await window.markpic(
Expand All @@ -11,63 +15,69 @@ const reply = await window.markpic(
)
```

`params` 必须是 JSON 字符串:WebView2 会把每个参数单独反序列化。前端统一在参数里带 `lang`(`zh` / `en`),Go 侧据此返回对应语言的文案。
`params` must be a JSON string: WebView2 deserializes each argument on its own. The
frontend always sends `lang` (`zh` / `en`) inside the params, and the Go side uses it to
pick the wording.

## 响应
## Replies

```json
{ "ok": true, "data": { } }
{ "ok": false, "code": "conflict", "message": "已经有一轮在跑了" }
```

失败不会 reject Promise;界面按 `code` 分支、把 `message` 展示给用户。
Failures never reject the promise; the UI branches on `code` and shows `message`.

| code | 含义 |
| code | meaning |
| --- | --- |
| `bad_request` | 参数不合法 |
| `conflict` | 同一页已有一轮在跑,或状态冲突 |
| `unsupported` | 当前平台不支持(例如原生对话框) |
| `not_found` | 未知方法 |
| `internal` | 服务端内部错误 |
| `bad_request` | invalid params |
| `conflict` | a run is already going on this page, or the state conflicts |
| `unsupported` | not available on this platform (native dialogs, for example) |
| `not_found` | unknown method |
| `internal` | internal server error |

## 方法
## Methods

| 方法 | 参数 | 返回 |
| method | params | returns |
| --- | --- | --- |
| `app.hello` | `{lang}` | 版本、数据目录、语言 |
| `app.hello` | `{lang}` | version, data directory, language |
| `i18n.set` | `{lang}` | `{lang}` |
| `health` | — | PicGo 连通性等状态 |
| `settings.get` | — | 当前设置 |
| `settings.put` | 设置字段 | 保存后的设置 |
| `settings.closeAction` | `{action}` | `{closeAction}`;只改关闭行为,不碰未保存的设置草稿 |
| `health` | — | PicGo reachability and similar status |
| `settings.get` | — | current settings |
| `settings.put` | settings fields | the saved settings |
| `settings.closeAction` | `{action}` | `{closeAction}`; only the close behaviour, leaving an unsaved draft alone |
| `dialog.files` | — | `{paths}` |
| `dialog.folder` | — | `{paths}` |
| `preview` | `{paths, settings?}` | 扫描预览 |
| `scan.start` | `{scanId, paths, settings?}` | 已受理;结果通过 `scan.file` 推送 |
| `scan.cancel` | `{scanId, path?}` | `{cancelled}`;带 `path` 只取消那一份 |
| `run.start` | `{paths, settings?}` | 启动一轮转换;`mode` 由设置里的远程模式决定 |
| `run.current` | `{mode?}` | 该页当前那一轮的快照,用于界面重载后接回 |
| `preview` | `{paths, settings?}` | scan preview |
| `scan.start` | `{scanId, paths, settings?}` | accepted; results arrive as `scan.file` events |
| `scan.cancel` | `{scanId, path?}` | `{cancelled}`; with `path` only that file is cancelled |
| `run.start` | `{paths, settings?}` | starts a conversion run; `mode` comes from the remote mode in settings |
| `run.current` | `{mode?}` | the run this page already has, to reattach after a reload |
| `run.cancel` | `{runId}` | `{ok}` |
| `reveal` | `{path}` | `{ok}`;在资源管理器中定位 |
| `open` | `{target}` | `{ok}`;打开文件或目录 |
| `update.status` | — | 当前更新状态(不联网) |
| `update.check` | — | 检查更新;失败原因写在 `status.error` |
| `update.install` | — | 下载、校验、替换并重启 |
| `reveal` | `{path}` | `{ok}`; reveal in the file manager |
| `open` | `{target}` | `{ok}`; open a file or folder |
| `update.status` | — | current update state (offline) |
| `update.check` | — | check for updates; the reason for a failure lands in `status.error` |
| `update.install` | — | download, verify, replace and restart |

## 事件
## Events

Go 侧通过 `window.__markpicEvents(payload)` 推送。`payload` 可以是单个事件,也可以是事件数组;终止事件(`run.finished`、`run.cancelled`、`scan.done`)不批量延迟。
Go pushes through `window.__markpicEvents(payload)`. `payload` is either a single event
or an array of events; terminal events (`run.finished`, `run.cancelled`, `scan.done`) are
never batched or delayed.

| type | 关键字段 |
| type | key fields |
| --- | --- |
| `run.started` | `runId`、`mode`、`files` |
| `file.started` | `runId`、`id` |
| `file.progress` | `runId`、`id`、`uploaded`、`done`、`total`、`items` |
| `file.finished` | `runId`、`id`、`result` |
| `run.started` | `runId`, `mode`, `files` |
| `file.started` | `runId`, `id` |
| `file.progress` | `runId`, `id`, `uploaded`, `done`, `total`, `items` |
| `file.finished` | `runId`, `id`, `result` |
| `run.cancelled` | `runId` |
| `run.finished` | `runId`、`summary` |
| `log` | `level`、`message` |
| `scan.file` | `runId`(扫描时放 `scanId`)、`path`、`scanned`、`cancelled`、`timedOut` |
| `scan.done` | `runId`(扫描时放 `scanId`) |
| `run.finished` | `runId`, `summary` |
| `log` | `level`, `message` |
| `scan.file` | `runId` (`scanId` when scanning), `path`, `scanned`, `cancelled`, `timedOut` |
| `scan.done` | `runId` (`scanId` when scanning) |

`run.started` 里的 `mode` 区分上传 / 检测 / 下载三页,界面按它认领自己的那一轮。页面刷新后先调 `run.current` 拿回当前快照,再继续接收事件。
`mode` in `run.started` tells the three pages apart (upload / check / download); each
page claims the run that belongs to it. After a page refresh, call `run.current` first
to get the current snapshot, then keep receiving events.
Loading