frontend: let the writer set a figure's size in the editor

Figures come out of a plotting tool at whatever size they were made. On the
paper this was written for, the sixteen of them are 1441, 1857, 2409 and 4169
pixels wide — every one wider than the 1276px column — so with no size they all
printed at the full width, and the near-square ones (1857×1986, 1974×2068) took
1365px of height, a page each. Measured in the browser, all sixteen came out at
exactly 1276px: not one of them was the size its author wanted.

`{width=…}` has been in the syntax all along, so this is the control that was
missing, not the feature. A row that is a figure now carries 宽度 in its header:
25/50/70/100%, or any value typed in — the size a panel wants is what it
measures, not a round number — with 原尺寸 as the empty value. Beside it, what
the picture will measure on the page (`原图 1857×1986 · 显示 893×955`), worked
out against the column actually rendered behind the dialog, which is the number
the writer is deciding with.

Two rules keep it honest. The value goes through `parseImageWidth` — the same
function that parses the attribute when the paper is printed — so what the
control shows is what will be printed, and a value it cannot read is refused
with the forms that work instead of stored as a size that quietly does nothing.
And the attribute is written into the sentence content by `withImageWidth`,
which edits only the first picture: the control is offered for a figure, and a
sentence with words around its picture is not one. Reading the size back out of
the content rather than keeping a copy of it in the draft means there is one
place it can be wrong instead of two.

`check-image.mjs` grows from 15 checks to 24, driving the real control: that
only figure rows offer one, that it shows what each is set to, that typing 30%
converts to 383×239 immediately, that what was typed is what gets stored, that
the paper then prints it at 30% of the column, that clearing it goes back to the
natural 480×300, and that "宽一点" is refused while the sentence keeps its size.

The MCP side of the same rule was wrong and is fixed with it: `image_upload(width=
"60")` wrote `{width=60px}`, and the reader takes a bare number as a share of the
column — `parseImageWidth` only reads pixels when the value says `px`. A model
asking for 60% got a 60-pixel figure. v7 is deployed with the corrected reading,
and smoke_mcp.py checks it.
This commit is contained in:
2026-09-24 11:25:18 +08:00
parent 9e6a1f8c3e
commit 48f0c12fd2
9 changed files with 357 additions and 12 deletions
+6
View File
@@ -471,6 +471,12 @@ Header: Authorization: Bearer <MCP_HTTP_TOKEN>
`width` 写法宽容(`70%`、`70 %`、`{width=70%}`、`w=400px` 都收),含义严格:像素 1–4000、百分比 1–100,
超出会被拒绝而不是默默忽略——网页端读不懂的尺寸会退回原尺寸,那等于写了个不生效的值。
**只写数字按百分比算**(`60` = `60%`),和网页端一致:只有写成 `px` 才算像素,因为这是
`frontend/src/utils/rich.ts` 里 `parseImageWidth` 的读法,页面和工具必须读同一种。
同一个大小在网页端也能改:段落编辑器里,凡是"整句只有一张图"的行都会出现「宽度」下拉框,
可以选 25/50/70/100%,也可以直接填任意值(如 `63%`、`380px`),旁边实时显示这会在版面上
占多大(如 `原图 1857×1986 · 显示 893×955`)。
存储没配好(缺 `MINIO_ENDPOINT` / `MINIO_ACCESS_KEY` / `MINIO_SECRET_KEY`)时,这个工具报 503 语义的说明,
**写作路径照常**:论文、段落、句子、模板、文献都不碰对象存储。
+17 -1
View File
@@ -413,7 +413,23 @@ line":
The size is optional and comes from pandoc's attribute form — `{width=70%}`,
`{width=400px}` — and is validated to digits plus one unit before it becomes a
CSS length, so no second declaration can be smuggled through it.
CSS length, so no second declaration can be smuggled through it. A bare number
is a **share of the column**, because `parseImageWidth` only reads a value as
pixels when it says `px`; the MCP tool that writes the same attribute follows
that rule rather than inventing its own.
Leaving the size off means the picture prints at its own width, capped to the
column — and that turned out to be the wrong default to *live* with. Figures
come out of a plotting tool at whatever size they were made: one paper's are
1441, 1857, 2409 and 4169 pixels wide, so every one of them is wider than the
1276px column and they all printed at the full width, with the near-square ones
(1857×1986, 1974×2068) filling a whole page at 1365px tall. A written size is
therefore part of the editor: a row that is a figure carries a 宽度 control —
presets, or any value typed in — and beside it what the picture will measure on
the page (`原图 1857×1986 · 显示 893×955`), measured against the real column
behind the dialog. The control writes the attribute through the reader's own
`parseImageWidth`, so what it shows is what gets printed, and a value that
function cannot read is refused instead of stored as a size that does nothing.
Configuration is three variables (`MINIO_ENDPOINT`, `MINIO_ACCESS_KEY`,
`MINIO_SECRET_KEY`, plus `MINIO_BUCKET`). Left empty, the paper still writes and