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
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"log"
"os"
"strings"
)
// cardWideTableGroupingDisabled reports whether the DingTalk final-frame
// normalizer must stop rewriting over-wide answer tables into grouped lists.
// Disabling it keeps real tables in the card, which is what the operator wants
// now that the PC client renders wide-screen cards; clients that still cannot
// lay out wide tables need the grouping, so the default stays enabled.
// DINGTALK_CARD_WIDE_TABLE_GROUP=off disables it.
func cardWideTableGroupingDisabled() bool {
switch strings.ToLower(strings.TrimSpace(os.Getenv("DINGTALK_CARD_WIDE_TABLE_GROUP"))) {
case "off", "0", "false", "no":
log.Printf("DingTalk wide-table grouping disabled by configuration")
return true
default:
return false
}
}
+2 -1
View File
@@ -323,7 +323,8 @@ func main() {
ReasoningRouter: &dingTalkReasoningRouter{service: reasoningService},
LanguageResolver: settingsRuntime.repository,
OutboundRewriteTimeout: outboundImages.rewriteTimeout,
OutboundRewriteTimeout: outboundImages.rewriteTimeout,
WideTableGroupingDisabled: cardWideTableGroupingDisabled(),
},
)
if err != nil {
+15
View File
@@ -215,6 +215,21 @@ func TestOutboundImageBudgetAndCompressionDefaults(t *testing.T) {
}
}
func TestCardWideTableGroupingDisabledToggle(t *testing.T) {
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "")
if cardWideTableGroupingDisabled() {
t.Fatal("wide-table grouping must default to enabled")
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "off")
if !cardWideTableGroupingDisabled() {
t.Fatal("DINGTALK_CARD_WIDE_TABLE_GROUP=off must disable wide-table grouping")
}
t.Setenv("DINGTALK_CARD_WIDE_TABLE_GROUP", "ON")
if cardWideTableGroupingDisabled() {
t.Fatal("any value other than off must keep grouping enabled")
}
}
func TestMainDoesNotExposeWebAdministrationOrSetupOnlyMode(t *testing.T) {
data, err := os.ReadFile("main.go")
if err != nil {