feat(dingtalk): make wide-table grouping switchable for wide-screen PC cards

DINGTALK_CARD_WIDE_TABLE_GROUP=off keeps over-wide answer tables as tables on the final frame (still replaces <br> inside cells) so the PC wide-screen card can lay them out itself.
This commit is contained in:
hermes
2026-09-18 11:45:55 +08:00
parent 882ac62433
commit 92324b4242
6 changed files with 138 additions and 8 deletions
+14 -3
View File
@@ -168,6 +168,10 @@ type HandlerOptions struct {
// delivery timeout, otherwise the remaining images are dropped. Zero keeps
// finalDeliveryTimeout.
OutboundRewriteTimeout time.Duration
// WideTableGroupingDisabled stops the final-frame normalizer from rewriting
// over-wide tables into grouped lists. Leave false on clients whose cards
// cannot lay out wide tables.
WideTableGroupingDisabled bool
}
type Handler struct {
@@ -189,6 +193,10 @@ type Handler struct {
// outboundRewriteTimeout applies to the image rewrite stage only; zero
// falls back to finalDeliveryTimeout.
outboundRewriteTimeout time.Duration
// wideTableGroupingDisabled keeps the final frame's tables as tables
// instead of rewriting over-wide ones into grouped lists. Used while the
// client renders wide tables itself (PC wide-screen cards).
wideTableGroupingDisabled bool
}
// NewHandler accepts at most one image downloader. A nil/omitted downloader
@@ -237,7 +245,8 @@ func NewHandlerWithOptions(cfg TenantConfig, qa QAAsker, reply MarkdownSender, o
cardUpdateInterval: 500 * time.Millisecond,
finalDeliveryTimeout: defaultHTTPTimeout,
outboundRewriteTimeout: opts.OutboundRewriteTimeout,
outboundRewriteTimeout: opts.OutboundRewriteTimeout,
wideTableGroupingDisabled: opts.WideTableGroupingDisabled,
}, nil
}
@@ -660,8 +669,10 @@ func (h *Handler) finalizeCardOrMarkdown(ctx context.Context, webhookURL string,
}
func (h *Handler) rewriteOutboundContent(ctx context.Context, content string) string {
options := defaultTableNormalizeOptions()
options.groupWideTables = !h.wideTableGroupingDisabled
if h.outboundRewriter == nil {
return normalizeWideMarkdownTables(sanitizeDisplayAnswer(content))
return normalizeMarkdownTables(sanitizeDisplayAnswer(content), options)
}
timeout := h.outboundRewriteTimeout
if timeout <= 0 {
@@ -672,7 +683,7 @@ func (h *Handler) rewriteOutboundContent(ctx context.Context, content string) st
}
rewriteCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), timeout)
defer cancel()
return normalizeWideMarkdownTables(sanitizeDisplayAnswer(h.outboundRewriter.Rewrite(rewriteCtx, content)))
return normalizeMarkdownTables(sanitizeDisplayAnswer(h.outboundRewriter.Rewrite(rewriteCtx, content)), options)
}
func (h *Handler) sanitizeOutboundPartial(ctx context.Context, content string) string {