Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix markdown links to multi-version CRDs #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
17 changes: 4 additions & 13 deletions renderer/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,22 @@ func (m *MarkdownRenderer) RenderTypeLink(t *types.Type) string {
}

if local {
return m.RenderLocalLink(text)
return m.RenderLocalLink(link, text)
} else {
return m.RenderExternalLink(link, text)
}
}

func (m *MarkdownRenderer) RenderLocalLink(text string) string {
anchor := strings.ToLower(
strings.NewReplacer(
" ", "-",
".", "",
"/", "",
"(", "",
")", "",
).Replace(text),
)
return fmt.Sprintf("[%s](#%s)", text, anchor)
func (m *MarkdownRenderer) RenderLocalLink(link, text string) string {
return fmt.Sprintf("[%s](#%s)", text, link)
}

func (m *MarkdownRenderer) RenderExternalLink(link, text string) string {
return fmt.Sprintf("[%s](%s)", text, link)
}

func (m *MarkdownRenderer) RenderGVLink(gv types.GroupVersionDetails) string {
return m.RenderLocalLink(gv.GroupVersionString())
return m.RenderLocalLink(m.GroupVersionID(gv), gv.GroupVersionString())
}

func (m *MarkdownRenderer) RenderFieldDoc(text string) string {
Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/gv_details.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- define "gvDetails" -}}
{{- $gv := . -}}

## {{ $gv.GroupVersionString }}
## <a id="{{ markdownGroupVersionID $gv | markdownSafeID }}">{{ $gv.GroupVersionString }}</a>

{{ $gv.Doc }}

Expand Down
4 changes: 2 additions & 2 deletions templates/markdown/type.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- $type := . -}}
{{- if markdownShouldRenderType $type -}}

#### {{ $type.Name }}
#### <a id="{{ markdownTypeID $type | markdownSafeID }}">{{ $type.Name }}</a>

{{ if $type.IsAlias }}_Underlying type:_ _{{ markdownRenderTypeLink $type.UnderlyingType }}_{{ end }}

Expand Down Expand Up @@ -36,7 +36,7 @@ _Appears in:_

{{ end -}}

{{ if $type.EnumValues -}}
{{ if $type.EnumValues -}}
| Field | Description |
| --- | --- |
{{ range $type.EnumValues -}}
Expand Down
94 changes: 47 additions & 47 deletions test/expected.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# API Reference

## Packages
- [webapp.test.k8s.elastic.co/common](#webapptestk8selasticcocommon)
- [webapp.test.k8s.elastic.co/v1](#webapptestk8selasticcov1)
- [webapp.test.k8s.elastic.co/common](#webapp-test-k8s-elastic-co-common)
- [webapp.test.k8s.elastic.co/v1](#webapp-test-k8s-elastic-co-v1)


## webapp.test.k8s.elastic.co/common
## <a id="webapp-test-k8s-elastic-co-common">webapp.test.k8s.elastic.co/common</a>

Package common contains common API Schema definitions



#### CommonString
#### <a id="github-com-elastic-crd-ref-docs-api-common-commonstring">CommonString</a>

_Underlying type:_ _string_

Expand All @@ -20,25 +20,25 @@ _Underlying type:_ _string_


_Appears in:_
- [GuestbookSpec](#guestbookspec)
- [GuestbookStatus](#guestbookstatus)
- [GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)
- [GuestbookStatus](#github-com-elastic-crd-ref-docs-api-v1-guestbookstatus)




## webapp.test.k8s.elastic.co/v1
## <a id="webapp-test-k8s-elastic-co-v1">webapp.test.k8s.elastic.co/v1</a>

Package v1 contains API Schema definitions for the webapp v1 API group

### Resource Types
- [Embedded](#embedded)
- [Guestbook](#guestbook)
- [GuestbookList](#guestbooklist)
- [Underlying](#underlying)
- [Embedded](#github-com-elastic-crd-ref-docs-api-v1-embedded)
- [Guestbook](#github-com-elastic-crd-ref-docs-api-v1-guestbook)
- [GuestbookList](#github-com-elastic-crd-ref-docs-api-v1-guestbooklist)
- [Underlying](#github-com-elastic-crd-ref-docs-api-v1-underlying)



#### Embedded
#### <a id="github-com-elastic-crd-ref-docs-api-v1-embedded">Embedded</a>



Expand All @@ -59,7 +59,7 @@ Package v1 contains API Schema definitions for the webapp v1 API group
| `value` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#json-v1-apiextensions-k8s-io)_ | | | |


#### Embedded1
#### <a id="github-com-elastic-crd-ref-docs-api-v1-embedded1">Embedded1</a>



Expand All @@ -68,7 +68,7 @@ Package v1 contains API Schema definitions for the webapp v1 API group


_Appears in:_
- [Embedded](#embedded)
- [Embedded](#github-com-elastic-crd-ref-docs-api-v1-embedded)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
Expand All @@ -77,7 +77,7 @@ _Appears in:_
| `value` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#json-v1-apiextensions-k8s-io)_ | | | |


#### EmbeddedX
#### <a id="github-com-elastic-crd-ref-docs-api-v1-embeddedx">EmbeddedX</a>



Expand All @@ -86,16 +86,16 @@ _Appears in:_


_Appears in:_
- [Embedded](#embedded)
- [Embedded1](#embedded1)
- [Embedded](#github-com-elastic-crd-ref-docs-api-v1-embedded)
- [Embedded1](#github-com-elastic-crd-ref-docs-api-v1-embedded1)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `x` _string_ | | | |
| `value` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#json-v1-apiextensions-k8s-io)_ | | | |


#### Guestbook
#### <a id="github-com-elastic-crd-ref-docs-api-v1-guestbook">Guestbook</a>



Expand All @@ -104,17 +104,17 @@ Guestbook is the Schema for the guestbooks API.


_Appears in:_
- [GuestbookList](#guestbooklist)
- [GuestbookList](#github-com-elastic-crd-ref-docs-api-v1-guestbooklist)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `apiVersion` _string_ | `webapp.test.k8s.elastic.co/v1` | | |
| `kind` _string_ | `Guestbook` | | |
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
| `spec` _[GuestbookSpec](#guestbookspec)_ | | \{ page:1 \} | |
| `spec` _[GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)_ | | \{ page:1 \} | |


#### GuestbookEntry
#### <a id="github-com-elastic-crd-ref-docs-api-v1-guestbookentry">GuestbookEntry</a>



Expand All @@ -123,17 +123,17 @@ GuestbookEntry defines an entry in a guest book.


_Appears in:_
- [GuestbookSpec](#guestbookspec)
- [GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `name` _string_ | Name of the guest (pipe \| should be escaped) | | MaxLength: 80 <br />Pattern: `0*[a-z0-9]*[a-z]*[0-9]` <br /> |
| `time` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta)_ | Time of entry | | |
| `comment` _string_ | Comment by guest. This can be a multi-line comment.<br />Like this one.<br />Now let's test a list:<br />* a<br />* b<br /><br />Another isolated comment.<br /><br />Looks good? | | Pattern: `0*[a-z0-9]*[a-z]*[0-9]*\|\s` <br /> |
| `rating` _[Rating](#rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |
| `rating` _[Rating](#github-com-elastic-crd-ref-docs-api-v1-rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |


#### GuestbookHeader
#### <a id="github-com-elastic-crd-ref-docs-api-v1-guestbookheader">GuestbookHeader</a>

_Underlying type:_ _string_

Expand All @@ -142,11 +142,11 @@ GuestbookHeaders are strings to include at the top of a page.


_Appears in:_
- [GuestbookSpec](#guestbookspec)
- [GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)



#### GuestbookList
#### <a id="github-com-elastic-crd-ref-docs-api-v1-guestbooklist">GuestbookList</a>



Expand All @@ -161,10 +161,10 @@ GuestbookList contains a list of Guestbook.
| `apiVersion` _string_ | `webapp.test.k8s.elastic.co/v1` | | |
| `kind` _string_ | `GuestbookList` | | |
| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
| `items` _[Guestbook](#guestbook) array_ | | | |
| `items` _[Guestbook](#github-com-elastic-crd-ref-docs-api-v1-guestbook) array_ | | | |


#### GuestbookSpec
#### <a id="github-com-elastic-crd-ref-docs-api-v1-guestbookspec">GuestbookSpec</a>



Expand All @@ -173,22 +173,22 @@ GuestbookSpec defines the desired state of Guestbook.


_Appears in:_
- [Guestbook](#guestbook)
- [Guestbook](#github-com-elastic-crd-ref-docs-api-v1-guestbook)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `page` _[PositiveInt](#positiveint)_ | Page indicates the page number | 1 | Minimum: 1 <br /> |
| `entries` _[GuestbookEntry](#guestbookentry) array_ | Entries contain guest book entries for the page | | |
| `page` _[PositiveInt](#github-com-elastic-crd-ref-docs-api-v1-positiveint)_ | Page indicates the page number | 1 | Minimum: 1 <br /> |
| `entries` _[GuestbookEntry](#github-com-elastic-crd-ref-docs-api-v1-guestbookentry) array_ | Entries contain guest book entries for the page | | |
| `selector` _[LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#labelselector-v1-meta)_ | Selector selects something | | |
| `headers` _[GuestbookHeader](#guestbookheader) array_ | Headers contains a list of header items to include in the page | | MaxItems: 10 <br />UniqueItems: true <br /> |
| `headers` _[GuestbookHeader](#github-com-elastic-crd-ref-docs-api-v1-guestbookheader) array_ | Headers contains a list of header items to include in the page | | MaxItems: 10 <br />UniqueItems: true <br /> |
| `certificateRef` _[SecretObjectReference](https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.SecretObjectReference)_ | CertificateRef is a reference to a secret containing a certificate | | |
| `str` _[CommonString](#commonstring)_ | | | |
| `enum` _[MyEnum](#myenum)_ | Enumeration is an example of an aliased enumeration type | | Enum: [MyFirstValue MySecondValue] <br /> |
| `str` _[CommonString](#github-com-elastic-crd-ref-docs-api-common-commonstring)_ | | | |
| `enum` _[MyEnum](#github-com-elastic-crd-ref-docs-api-v1-myenum)_ | Enumeration is an example of an aliased enumeration type | | Enum: [MyFirstValue MySecondValue] <br /> |




#### MyEnum
#### <a id="github-com-elastic-crd-ref-docs-api-v1-myenum">MyEnum</a>

_Underlying type:_ _string_

Expand All @@ -198,15 +198,15 @@ _Validation:_
- Enum: [MyFirstValue MySecondValue]

_Appears in:_
- [GuestbookSpec](#guestbookspec)
- [GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)

| Field | Description |
| --- | --- |
| `MyFirstValue` | MyFirstValue is an interesting value to use<br /> |
| `MySecondValue` | MySecondValue is what you use when you can't use MyFirstValue<br /> |


#### PositiveInt
#### <a id="github-com-elastic-crd-ref-docs-api-v1-positiveint">PositiveInt</a>

_Underlying type:_ _integer_

Expand All @@ -216,11 +216,11 @@ _Validation:_
- Minimum: 1

_Appears in:_
- [GuestbookSpec](#guestbookspec)
- [GuestbookSpec](#github-com-elastic-crd-ref-docs-api-v1-guestbookspec)



#### Rating
#### <a id="github-com-elastic-crd-ref-docs-api-v1-rating">Rating</a>

_Underlying type:_ _integer_

Expand All @@ -231,13 +231,13 @@ _Validation:_
- Minimum: 1

_Appears in:_
- [GuestbookEntry](#guestbookentry)
- [GuestbookEntry](#github-com-elastic-crd-ref-docs-api-v1-guestbookentry)





#### Underlying
#### <a id="github-com-elastic-crd-ref-docs-api-v1-underlying">Underlying</a>



Expand All @@ -252,24 +252,24 @@ Underlying tests that Underlying1's underlying type is Underlying2 instead of st
| `apiVersion` _string_ | `webapp.test.k8s.elastic.co/v1` | | |
| `kind` _string_ | `Underlying` | | |
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
| `a` _[Underlying1](#underlying1)_ | | b | MaxLength: 10 <br /> |
| `a` _[Underlying1](#github-com-elastic-crd-ref-docs-api-v1-underlying1)_ | | b | MaxLength: 10 <br /> |


#### Underlying1
#### <a id="github-com-elastic-crd-ref-docs-api-v1-underlying1">Underlying1</a>

_Underlying type:_ _[Underlying2](#underlying2)_
_Underlying type:_ _[Underlying2](#github-com-elastic-crd-ref-docs-api-v1-underlying2)_

Underlying1 has an underlying type with an underlying type

_Validation:_
- MaxLength: 10

_Appears in:_
- [Underlying](#underlying)
- [Underlying](#github-com-elastic-crd-ref-docs-api-v1-underlying)



#### Underlying2
#### <a id="github-com-elastic-crd-ref-docs-api-v1-underlying2">Underlying2</a>

_Underlying type:_ _string_

Expand All @@ -279,7 +279,7 @@ _Validation:_
- MaxLength: 10

_Appears in:_
- [Underlying1](#underlying1)
- [Underlying1](#github-com-elastic-crd-ref-docs-api-v1-underlying1)



Loading