Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gen-apidocs/generators/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package generators
import (
_ "embed"
"fmt"
"html"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -460,7 +461,7 @@ func (m *MarkdownWriter) buildDefinitionPage(d *api.Definition, currentCategory
Title: d.Name,
Weight: m.nextResourceWeight(),
Anchor: anchor(d.Name),
Description: d.DescriptionWithEntities,
Description: html.UnescapeString(d.DescriptionWithEntities),
}

// Inline closure rooted at d gates which types may flatten inline;
Expand Down Expand Up @@ -856,6 +857,7 @@ func anchor(s string) string {
// escape covers the only markdown-breaking character in OpenAPI descriptions:
// raw `<` that would otherwise be read as HTML.
func escape(s string) string {
s = html.UnescapeString(s)
s = strings.ReplaceAll(s, "<", `\<`)
s = enumHeaderRegex.ReplaceAllString(s, "<br/><br/>Possible enum values:")
s = enumBulletRegex.ReplaceAllString(s, "<br/> - `")
Expand Down
18 changes: 12 additions & 6 deletions gen-apidocs/generators/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func TestEscape(t *testing.T) {
if got := escape("no change"); got != "no change" {
t.Errorf("escape: got %q", got)
}
if got := escape(`Name: &#34;mysvc&#34;`); got != `Name: "mysvc"` {
t.Errorf("escape quotes: got %q", got)
}
if got := escape("https://git.k8s.io/community?foo=1&amp;bar=2"); got != "https://git.k8s.io/community?foo=1&bar=2" {
t.Errorf("escape url amp: got %q", got)
}
if got := escape("Allowed values. Possible enum values: - `\"A\"` first. - `\"B\"` second."); got != "Allowed values.<br/><br/>Possible enum values:<br/> - `\"A\"` first.<br/> - `\"B\"` second." {
t.Errorf("escape enum list: got %q", got)
}
Expand Down Expand Up @@ -117,10 +123,10 @@ func TestWritePipeTable(t *testing.T) {

func TestOperationSlug(t *testing.T) {
cases := map[string]string{
"listCoreV1Pod": "listcorev1pod",
"readAppsV1NamespacedDeployment": "readappsv1namespaceddeployment",
"watchCore.V1.Pod": "watchcore-v1-pod",
"Some/Weird ID": "some-weird-id",
"listCoreV1Pod": "listcorev1pod",
"readAppsV1NamespacedDeployment": "readappsv1namespaceddeployment",
"watchCore.V1.Pod": "watchcore-v1-pod",
"Some/Weird ID": "some-weird-id",
}
for in, want := range cases {
if got := operationSlug(in); got != want {
Expand Down Expand Up @@ -405,8 +411,8 @@ func TestLinkDefinitionsSkipsInlined(t *testing.T) {
m := &MarkdownWriter{
linkMap: map[string]linkInfo{},
classifications: map[string]defClassification{
azureDisk.Key(): {Mode: classifyInline}, // InlineInto irrelevant for this test
objectMeta.Key(): {Mode: classifyStandalone},
azureDisk.Key(): {Mode: classifyInline}, // InlineInto irrelevant for this test
objectMeta.Key(): {Mode: classifyStandalone},
},
}

Expand Down