Skip to content

Commit 458b8a2

Browse files
committed
encode JSON examples to avoid mdx acorn rendering error
Signed-off-by: Phil Prasek <prasek@gmail.com>
1 parent a336389 commit 458b8a2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

temporalcli/commandsgen/docs.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commandsgen
33
import (
44
"bytes"
55
"fmt"
6+
"regexp"
67
"sort"
78
"strings"
89
)
@@ -151,7 +152,7 @@ func (w *docWriter) writeCommandOptions() {
151152
if len(option.Usages) == 1 {
152153
usageDescription := option.Usages[0]
153154
usage := usageDescription.UsageSites[0]
154-
w.fileMap[fileName].WriteString(usage.Option.Description + "\n\n")
155+
w.fileMap[fileName].WriteString(encodeJSONExample(usage.Option.Description) + "\n\n")
155156

156157
if usage.Option.Experimental {
157158
w.fileMap[fileName].WriteString(":::note" + "\n\n")
@@ -164,7 +165,7 @@ func (w *docWriter) writeCommandOptions() {
164165
w.fileMap[fileName].WriteString("\n")
165166

166167
}
167-
w.fileMap[fileName].WriteString(usageDescription.OptionDescription + "\n\n")
168+
w.fileMap[fileName].WriteString(encodeJSONExample(usageDescription.OptionDescription) + "\n\n")
168169

169170
for _, usage := range usageDescription.UsageSites {
170171
experimentalDescr := ""
@@ -213,3 +214,10 @@ func (w *docWriter) writeCommandOptions() {
213214
}
214215
*/
215216
}
217+
218+
func encodeJSONExample(v string) string {
219+
// example: `'YourKey={"your": "value"}'`
220+
re := regexp.MustCompile(`('[a-zA-Z0-9]*={.*}')`)
221+
v = re.ReplaceAllString(v, "`$1`")
222+
return v
223+
}

0 commit comments

Comments
 (0)