Skip to content

Commit 3c23d41

Browse files
committed
feat: add escape handling for pipe characters in Asciidoctor rendering
1 parent f2d7ee3 commit 3c23d41

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

renderer/asciidoctor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func (adr *AsciidoctorRenderer) RenderFieldDoc(text string) string {
169169

170170
func (adr *AsciidoctorRenderer) RenderValidation(text string) string {
171171
renderedText := escapeFirstAsterixInEachPair(text)
172+
renderedText = escapePipe(renderedText)
172173
return escapeCurlyBraces(renderedText)
173174
}
174175

@@ -190,6 +191,12 @@ func escapeFirstAsterixInEachPair(text string) string {
190191
return text
191192
}
192193

194+
// escapePipe ensures sufficient escapes are added to pipe characters, so they are not mistaken
195+
// for asciidoctor table formatting.
196+
func escapePipe(text string) string {
197+
return strings.Replace(text, "|", "\\|", -1)
198+
}
199+
193200
// escapeCurlyBraces ensures sufficient escapes are added to curly braces, so they are not mistaken
194201
// for asciidoctor id attributes.
195202
func escapeCurlyBraces(text string) string {

test/expected.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Now let's test a list: +
175175

176176
Another isolated comment. +
177177

178-
Looks good? + | | Pattern: `0\*[a-z0-9]*[a-z]\*[0-9]*|\s` +
178+
Looks good? + | | Pattern: `0\*[a-z0-9]*[a-z]\*[0-9]*\|\s` +
179179

180180
| *`rating`* __xref:{anchor_prefix}-github-com-elastic-crd-ref-docs-api-v1-rating[$$Rating$$]__ | Rating provided by the guest + | | Maximum: 5 +
181181
Minimum: 1 +

0 commit comments

Comments
 (0)