Skip to content

markdownRenderFieldDoc incorrectly escapes braces inside code spans #205

Open

Description

@lmilbaum

Problem

markdownRenderFieldDoc escapes { and } as \{ and \} throughout field and validation text, including inside code spans (backtick-quoted strings). In CommonMark, backslash escaping is not processed inside code spans, so the backslashes are rendered literally instead of being consumed.

Reproduction

A field with a kubebuilder validation pattern:

```go
// +kubebuilder:validation:Pattern=^[A-Z][a-zA-Z0-9]{0,62}$
```

The default Markdown templates render the Validation column using markdownRenderFieldDoc:

```
{{ range .Validation }} {{ markdownRenderFieldDoc . }}
{{ end }}
```

Actual output in the table cell:
```
Pattern: ^[A-Z][a-zA-Z0-9]\{0,62\}$
```

Expected output:
```
Pattern: ^[A-Z][a-zA-Z0-9]{0,62}$
```

The \{ and \} sequences appear literally inside the code span because CommonMark does not process backslash escapes inside code spans (spec §6.3).

The same issue affects markdownRenderFieldDoc calls in type_members.tpl when field descriptions contain inline code with {/}.

Context

Encountered while generating API reference docs for kubernetes-sigs/kro. Worked around it with a custom template helper that replaces markdownRenderFieldDoc and skips brace escaping entirely (kro PR: kubernetes-sigs/kro#1476).

Suggested fix

In markdownRenderFieldDoc, avoid escaping { and } that appear inside code spans (text surrounded by backticks). A simpler alternative is to not escape braces at all in the Markdown renderer — CommonMark does not require brace escaping in table cells, unlike MDX/JSX where {...} is a JSX expression. The escaping appears to have been added for MDX compatibility but breaks standard CommonMark.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions