Skip to content

Commit 03031f0

Browse files
authored
Merge pull request #4126 from afbjorklund/escape-markdown
Escape text in the command markdown documentation
2 parents f47b60e + 3777303 commit 03031f0

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cmd/limactl/copy.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ Backends:
3232
rsync - Uses rsync for faster transfers with resume capability (requires rsync on both host and guest)
3333
scp - Uses scp for reliable transfers (always available)
3434
35-
Examples:
35+
Not to be confused with 'limactl clone'.
36+
`
37+
38+
const copyExample = `
3639
# Copy file from guest to host (auto backend)
3740
limactl copy default:/etc/os-release .
3841
@@ -47,8 +50,6 @@ Examples:
4750
4851
# Copy multiple files
4952
limactl copy file1.txt file2.txt default:/tmp/
50-
51-
Not to be confused with 'limactl clone'.
5253
`
5354

5455
type copyTool string
@@ -72,6 +73,7 @@ func newCopyCommand() *cobra.Command {
7273
Aliases: []string{"cp"},
7374
Short: "Copy files between host and guest",
7475
Long: copyHelp,
76+
Example: copyExample,
7577
Args: WrapArgsError(cobra.MinimumNArgs(2)),
7678
RunE: copyAction,
7779
GroupID: advancedCommand,

cmd/limactl/gendoc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,26 @@ and $LIMA_WORKDIR.
101101
return doc.GenManTree(cmd.Root(), header, dir)
102102
}
103103

104+
func escapeMarkdown(text string) string {
105+
lines := strings.Split(text, "\n")
106+
for i := range lines {
107+
// Need to escape backticks first, before adding more
108+
for _, c := range strings.Split("\\`*_[]()#+-.|", "") {
109+
lines[i] = strings.ReplaceAll(lines[i], c, "\\"+c)
110+
}
111+
if i < len(lines)-1 {
112+
if lines[i] != "" && lines[i+1] != "" {
113+
lines[i] += " " // line break
114+
}
115+
}
116+
}
117+
return strings.Join(lines, "\n")
118+
}
119+
104120
func genDocsy(cmd *cobra.Command, dir string) error {
121+
for _, c := range cmd.Root().Commands() {
122+
c.Long = escapeMarkdown(c.Long)
123+
}
105124
return doc.GenMarkdownTreeCustom(cmd.Root(), dir, func(s string) string {
106125
// Replace limactl_completion_bash to completion bash for docsy title
107126
name := filepath.Base(s)

0 commit comments

Comments
 (0)