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() }