diff --git a/gen-resourcesdocs/pkg/outputs/kwebsite/section.go b/gen-resourcesdocs/pkg/outputs/kwebsite/section.go
index 30aabbc354..e706892ceb 100644
--- a/gen-resourcesdocs/pkg/outputs/kwebsite/section.go
+++ b/gen-resourcesdocs/pkg/outputs/kwebsite/section.go
@@ -2,6 +2,8 @@ package kwebsite
import (
"fmt"
+ "html"
+ "regexp"
"sort"
"strings"
@@ -19,7 +21,22 @@ type Section struct {
// AddContent adds content to a section
func (o Section) AddContent(s string) error {
i := len(o.chapter.data.Sections)
- o.chapter.data.Sections[i-1].Description = s
+
+ // Regular expression to find code blocks
+ re := regexp.MustCompile("```(?s)(.*?)```")
+
+ // Replace code blocks with properly formatted HTML
+ processed := re.ReplaceAllStringFunc(s, func(match string) string {
+ // Remove the backticks and trim whitespace
+ code := strings.TrimSpace(strings.TrimPrefix(strings.TrimSuffix(match, "```"), "```"))
+ // Escape HTML special characters
+ code = html.EscapeString(code)
+ // Preserve line breaks
+ code = strings.ReplaceAll(code, "\n", "
")
+ return "
" + code + "
"
+ })
+
+ o.chapter.data.Sections[i-1].Description = processed
return nil
}