This commit is contained in:
“Naeel”
2026-07-17 09:51:57 +04:00
parent 6d69ae2c7c
commit 58675ccff2
3 changed files with 45 additions and 77 deletions
@@ -133,12 +133,51 @@ func buildManualPage(spec types.ServiceSpec, nav string) string {
if man == "" {
man = "Manual not available."
}
b.WriteString("<div class=\"man-content\">\n")
b.WriteString(man)
b.WriteString("\n</div>\n")
b.WriteString("<div class=\"man-content\">\n\n")
b.WriteString(htmlToMarkdown(man))
b.WriteString("\n\n</div>\n")
return b.String()
}
// htmlToMarkdown converts raw HTML to Markdown.
func htmlToMarkdown(s string) string {
// <br/> or <br> → newline
s = regexp.MustCompile(`<br\s*/?>`).ReplaceAllString(s, "\n")
// <h1>...</h1> → # ...
s = regexp.MustCompile(`<h1>(.*?)</h1>`).ReplaceAllString(s, "# $1")
// <h2>...</h2> → ## ...
s = regexp.MustCompile(`<h2>(.*?)</h2>`).ReplaceAllString(s, "## $1")
// <h3>...</h3> → ### ...
s = regexp.MustCompile(`<h3>(.*?)</h3>`).ReplaceAllString(s, "### $1")
// <strong> or <b> → **...**
s = regexp.MustCompile(`<(?:strong|b)>(.*?)</(?:strong|b)>`).ReplaceAllString(s, "**$1**")
// <em> or <i> → *...*
s = regexp.MustCompile(`<(?:em|i)>(.*?)</(?:em|i)>`).ReplaceAllString(s, "*$1*")
// <code>...</code> → `...`
s = regexp.MustCompile(`<code>(.*?)</code>`).ReplaceAllString(s, "`$1`")
// <a href="...">...</a> → [...](...)
s = regexp.MustCompile(`<a\s+href="(.*?)">(.*?)</a>`).ReplaceAllString(s, "[$2]($1)")
// <ul> / </ul> — remove
s = regexp.MustCompile(`</?ul>`).ReplaceAllString(s, "")
// <li>...</li> → - ...
s = regexp.MustCompile(`<li>(.*?)</li>`).ReplaceAllString(s, "- $1")
// <ol> / </ol> — remove
s = regexp.MustCompile(`</?ol>`).ReplaceAllString(s, "")
// <p> / </p> — remove
s = regexp.MustCompile(`</?p>`).ReplaceAllString(s, "")
// <pre> / </pre> — remove (content stays)
s = regexp.MustCompile(`</?pre>`).ReplaceAllString(s, "")
// <hr> or <hr/> → ---
s = regexp.MustCompile(`<hr\s*/?>`).ReplaceAllString(s, "\n---\n")
// Strip remaining HTML tags
s = regexp.MustCompile(`<[^>]+>`).ReplaceAllString(s, "")
// Decode HTML entities
s = html.UnescapeString(s)
// Collapse multiple blank lines
s = regexp.MustCompile(`\n{3,}`).ReplaceAllString(s, "\n\n")
return strings.TrimSpace(s)
}
func buildExamplePage(spec types.ServiceSpec, nav, version string, apiEndpoint string) string {
var b strings.Builder
b.WriteString(buildHeader(spec, nav))
@@ -169,7 +208,7 @@ func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string) st
b.WriteString("terraform {\n")
b.WriteString(" required_providers {\n")
b.WriteString(" nubes = {\n")
b.WriteString(" source = \"terra.k8c.ru/nubes/nubes\"\n")
b.WriteString(" source = \"registry.kube5s.ru/nubes-test/nubes\"\n")
b.WriteString(fmt.Sprintf(" version = \"%s\"\n", version))
b.WriteString(" }\n")
b.WriteString(" }\n")
@@ -424,7 +463,7 @@ func buildSubresourceExamplePage(spec types.ServiceSpec, srName string, nav stri
b.WriteString("terraform {\n")
b.WriteString(" required_providers {\n")
b.WriteString(" nubes = {\n")
b.WriteString(" source = \"terra.k8c.ru/nubes/nubes\"\n")
b.WriteString(" source = \"registry.kube5s.ru/nubes-test/nubes\"\n")
b.WriteString(fmt.Sprintf(" version = \"%s\"\n", version))
b.WriteString(" }\n")
b.WriteString(" }\n")