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:
+17
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user