feat(docs): auto-resize table column widths based on content#59
Open
SoIomon wants to merge 1 commit intolarksuite:mainfrom
Open
feat(docs): auto-resize table column widths based on content#59SoIomon wants to merge 1 commit intolarksuite:mainfrom
SoIomon wants to merge 1 commit intolarksuite:mainfrom
Conversation
edbd440 to
07c42ae
Compare
- After +create and +update, calculate optimal column widths from cell content - CJK/fullwidth characters count as 2 units, ASCII as 1, with cell padding - Clamp per-column widths to [80px, 400px]; normalize total to fit 700px container via two-pass scaling (second pass scales proportionally without min-floor to guarantee total ≤ container) - Skip update if computed widths are unchanged (avoids redundant PATCH calls) - Skip auto-resize in +update if markdown contains no tables (including borderless GFM tables: `A | B\n---|---\n1|2`) - Support text, heading, bullet, ordered, todo block types; handle rich inline elements (mention_doc, equation, link_preview, etc.) - Recursive cell traversal with cycle detection for nested block structures - Each column updated via separate PATCH (batch_update ignores multiple ops on same table) - Falls back gracefully on API errors (non-fatal warning only) - Adds docx:document:readonly and docx:document:write_only to docs +create scopes (required to read blocks and apply column-width patches post-creation)
07c42ae to
4edfa57
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs +createanddocs +updatebased on cell content lengthdocx:document:readonlyanddocx:document:write_onlytodocs +createscopes — required to read back block structure and apply column-width patches after document creationBefore / After
Files changed
table_auto_width.go— core logic: fetch blocks, calculate widths, normalize, update via APItable_auto_width_test.go— unit tests for width calculation, CJK handling, and normalizationdocs_create.go/docs_update.go— callautoResizeTableColumns()after doc creation/updateTest plan
go build ./...passesgo test ./shortcuts/doc/...passes