From 35aa50f76d35aa244f78bb36742f19f76a751d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Mon, 10 Aug 2026 13:12:17 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20HTML=20tables=20=E2=86=92=20Markdown=20t?= =?UTF-8?q?ables=20in=20docs-generator=20(mkdocs=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D1=80=D0=B5=D0=BD=D0=B4=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D1=82=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/writers/writers.go | 107 +++++++----------- 1 file changed, 41 insertions(+), 66 deletions(-) diff --git a/TOOLS/docs-generator/internal/writers/writers.go b/TOOLS/docs-generator/internal/writers/writers.go index f1cde9a..5cfe4de 100644 --- a/TOOLS/docs-generator/internal/writers/writers.go +++ b/TOOLS/docs-generator/internal/writers/writers.go @@ -552,28 +552,26 @@ func renderParamTable(params []types.ParamSpec, requiredTable, noDefault bool) s return "None.\n" } var b strings.Builder - tableClass := "resource-table resource-table-compact" - if requiredTable { - tableClass += " resource-table-required" - } - b.WriteString(fmt.Sprintf("\n", tableClass)) if noDefault { - b.WriteString("\n\n") + b.WriteString("| Code | Type | Description | Constraints |\n") + b.WriteString("|------|------|-------------|-------------|\n") } else { - b.WriteString("\n\n") + b.WriteString("| Code | Type | Default | Description | Constraints |\n") + b.WriteString("|------|------|---------|-------------|-------------|\n") } for _, p := range params { - b.WriteString("") - b.WriteString(fmt.Sprintf("", formatParamCode(p.Code))) - b.WriteString(fmt.Sprintf("", formatTypeCell(p))) - if !noDefault { - b.WriteString(fmt.Sprintf("", defaultCell(p.Default))) + code := formatParamCode(p.Code) + dtype := formatTypeCell(p) + desc := escapeText(pickTextTable(p)) + constr := escapeText(collectConstraints(p)) + if noDefault { + b.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", code, dtype, desc, constr)) + } else { + def := defaultCell(p.Default) + b.WriteString(fmt.Sprintf("| %s | %s | %s | %s | %s |\n", code, dtype, def, desc, constr)) } - b.WriteString(fmt.Sprintf("", escapeText(pickTextTable(p)))) - b.WriteString(fmt.Sprintf("", escapeText(collectConstraints(p)))) - b.WriteString("\n") } - b.WriteString("
CodeTypeDescriptionConstraints
CodeTypeDefaultDescriptionConstraints
%s%s%s%s%s
\n") + b.WriteString("\n") return b.String() } @@ -582,17 +580,16 @@ func renderModifyTable(params []types.ParamSpec) string { return "None.\n" } var b strings.Builder - b.WriteString("\n") - b.WriteString("\n\n") + b.WriteString("| Code | Type | Description | Constraints |\n") + b.WriteString("|------|------|-------------|-------------|\n") for _, p := range params { - b.WriteString("") - b.WriteString(fmt.Sprintf("", formatParamCode(p.Code))) - b.WriteString(fmt.Sprintf("", formatTypeCell(p))) - b.WriteString(fmt.Sprintf("", escapeText(pickTextTable(p)))) - b.WriteString(fmt.Sprintf("", escapeText(collectConstraints(p)))) - b.WriteString("\n") + code := formatParamCode(p.Code) + dtype := formatTypeCell(p) + desc := escapeText(pickTextTable(p)) + constr := escapeText(collectConstraints(p)) + b.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", code, dtype, desc, constr)) } - b.WriteString("
CodeTypeDescriptionConstraints
%s%s%s%s
\n") + b.WriteString("\n") return b.String() } @@ -750,7 +747,7 @@ func formatTypeCell(p types.ParamSpec) string { if dtype == "" { return "" } - return "" + escapeText(dtype) + "" + return "`" + dtype + "`" } func firstType(p types.ParamSpec) string { @@ -777,9 +774,9 @@ func defaultCell(value interface{}) string { return "" } if s, ok := value.(string); ok { - return "" + escapeText(s) + "" + return "`" + s + "`" } - return "" + escapeText(formatLiteral(value)) + "" + return "`" + formatLiteral(value) + "`" } func pickTextTable(p types.ParamSpec) string { @@ -869,35 +866,19 @@ func escapeText(value string) string { text = strings.ReplaceAll(text, "<br/>", "
") text = strings.ReplaceAll(text, "<br />", "
") text = strings.ReplaceAll(text, "<br>", "
") + // Escape pipe for markdown tables + text = strings.ReplaceAll(text, "|", "\\|") + // Replace literal newlines with
for markdown table cells + text = strings.ReplaceAll(text, "\n", "
") return text } func formatParamCode(code string) string { - return formatCode(ToSnake(code)) -} - -func formatCode(code string) string { - if code == "" { + snake := ToSnake(code) + if snake == "" { return "" } - if len(code) <= 40 { - return "" + code + "" - } - out := []string{} - prev := rune(0) - for _, ch := range code { - if ch == '_' { - out = append(out, "_") - prev = ch - continue - } - if prev != 0 && (unicodeIsLower(prev) || unicodeIsDigit(prev)) && unicodeIsUpper(ch) { - out = append(out, "") - } - out = append(out, string(ch)) - prev = ch - } - return "" + strings.Join(out, "") + "" + return "**`" + snake + "`**" } // ToSnake конвертирует CamelCase → snake_case. @@ -933,10 +914,6 @@ func ToSnake(value string) string { return strings.Trim(string(out), "_") } -func unicodeIsLower(r rune) bool { return r >= 'a' && r <= 'z' } -func unicodeIsUpper(r rune) bool { return r >= 'A' && r <= 'Z' } -func unicodeIsDigit(r rune) bool { return r >= '0' && r <= '9' } - func stripHTML(value string) string { if value == "" { return "" @@ -1026,23 +1003,21 @@ func renderNestedParams(p types.ParamSpec) string { label += " (map-fixed)" } b.WriteString(fmt.Sprintf("\n### %s\n\n", label)) - b.WriteString("\n") - b.WriteString("\n\n") + b.WriteString("| Code | Type | Required | Default | Description | Constraints |\n") + b.WriteString("|------|------|----------|---------|-------------|-------------|\n") for _, sp := range p.SubParams { req := "no" if sp.Required { req = "**yes**" } - b.WriteString("") - b.WriteString(fmt.Sprintf("", formatParamCode(sp.Code))) - b.WriteString(fmt.Sprintf("", formatTypeCell(sp))) - b.WriteString(fmt.Sprintf("", req)) - b.WriteString(fmt.Sprintf("", defaultCell(sp.Default))) - b.WriteString(fmt.Sprintf("", escapeText(pickTextTable(sp)))) - b.WriteString(fmt.Sprintf("", escapeText(collectConstraints(sp)))) - b.WriteString("\n") + code := formatParamCode(sp.Code) + dtype := formatTypeCell(sp) + def := defaultCell(sp.Default) + desc := escapeText(pickTextTable(sp)) + constr := escapeText(collectConstraints(sp)) + b.WriteString(fmt.Sprintf("| %s | %s | %s | %s | %s | %s |\n", code, dtype, req, def, desc, constr)) } - b.WriteString("
CodeTypeRequiredDefaultDescriptionConstraints
%s%s%s%s%s%s
\n") + b.WriteString("\n") return b.String() }