Skip to content

Commit

Permalink
encode JSON examples to avoid mdx acorn rendering error
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Prasek <[email protected]>
  • Loading branch information
prasek committed Oct 30, 2024
1 parent e3c65a2 commit 9528d68
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions temporalcli/commandsgen/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commandsgen
import (
"bytes"
"fmt"
"regexp"
"sort"
"strings"
)
Expand Down Expand Up @@ -151,7 +152,7 @@ func (w *docWriter) writeCommandOptions() {
if len(option.Usages) == 1 {
usageDescription := option.Usages[0]
usage := usageDescription.UsageSites[0]
w.fileMap[fileName].WriteString(usage.Option.Description + "\n\n")
w.fileMap[fileName].WriteString(encodeJSONExample(usage.Option.Description) + "\n\n")

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

}
w.fileMap[fileName].WriteString(usageDescription.OptionDescription + "\n\n")
w.fileMap[fileName].WriteString(encodeJSONExample(usageDescription.OptionDescription) + "\n\n")

for _, usage := range usageDescription.UsageSites {
experimentalDescr := ""
Expand Down Expand Up @@ -213,3 +214,10 @@ func (w *docWriter) writeCommandOptions() {
}
*/
}

func encodeJSONExample(v string) string {
// example: `'YourKey={"your": "value"}'`
re := regexp.MustCompile(`('[a-zA-Z0-9]*={.*}')`)
v = re.ReplaceAllString(v, "`$1`")
return v
}

0 comments on commit 9528d68

Please sign in to comment.