Skip to content

Commit d924e8d

Browse files
committed
fix: update docs-convert to handle more escaping
Also remove trailing whitespace on generated docs Signed-off-by: Justin Garrison <justin.garrison@siderolabs.com>
1 parent 38cfde0 commit d924e8d

37 files changed

Lines changed: 142 additions & 239 deletions

docs-convert/main.go

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func convertFile(srcPath, dstPath string) error {
3434
return err
3535
}
3636

37+
// Trim excessive trailing blank lines (keep at most 1)
38+
for len(lines) > 0 && strings.TrimSpace(lines[len(lines)-1]) == "" {
39+
lines = lines[:len(lines)-1]
40+
}
41+
3742
// Check if this is the v1alpha1/config file or cli file
3843
isConfigFile := strings.Contains(dstPath, "v1alpha1/config.mdx") || strings.Contains(dstPath, "v1alpha1\\config.mdx")
3944
isCliFile := strings.HasSuffix(dstPath, "/cli.mdx") || strings.HasSuffix(dstPath, "\\cli.mdx")
@@ -273,29 +278,53 @@ func escapeAngleBracketPlaceholders(line string) string {
273278
// Extract the content between < and >
274279
content := line[i+1 : end]
275280
// Check if it's likely a placeholder or text that should not be parsed as HTML
276-
// Known HTML tags we want to preserve: a, br, p, Accordion, details, summary, pre, code and their closing tags
281+
// Known HTML tags we want to preserve: a, br, p, Accordion, details, summary, pre, code, td, th, tr, table, thead, tbody and their closing tags
277282
isKnownTag := strings.HasPrefix(content, "a ") ||
283+
content == "a" ||
278284
strings.HasPrefix(content, "br") ||
279-
strings.HasPrefix(content, "p") ||
285+
content == "p" ||
286+
strings.HasPrefix(content, "p ") ||
280287
strings.HasPrefix(content, "Accordion") ||
281288
strings.HasPrefix(content, "details") ||
282289
strings.HasPrefix(content, "summary") ||
283290
strings.HasPrefix(content, "pre") ||
291+
content == "pre" ||
284292
strings.HasPrefix(content, "code") ||
293+
content == "code" ||
294+
strings.HasPrefix(content, "td") ||
295+
content == "td" ||
296+
strings.HasPrefix(content, "th") ||
297+
content == "th" ||
298+
strings.HasPrefix(content, "tr") ||
299+
content == "tr" ||
300+
strings.HasPrefix(content, "table") ||
301+
strings.HasPrefix(content, "thead") ||
302+
strings.HasPrefix(content, "tbody") ||
285303
content == "/a" ||
286304
content == "/br" ||
287305
content == "/p" ||
288306
content == "/Accordion" ||
289307
content == "/details" ||
290308
content == "/summary" ||
291309
content == "/pre" ||
292-
content == "/code"
310+
content == "/code" ||
311+
content == "/td" ||
312+
content == "/th" ||
313+
content == "/tr" ||
314+
content == "/table" ||
315+
content == "/thead" ||
316+
content == "/tbody"
293317

294318
// If it's not a known HTML tag, escape using JSX expressions
295319
if !isKnownTag {
296320
result += `{"<"}` + content + `{">"}`
297321
i = end + 1
298322
continue
323+
} else {
324+
// For known HTML tags, copy the entire tag at once
325+
result += line[i : end+1]
326+
i = end + 1
327+
continue
299328
}
300329
}
301330
}
@@ -469,13 +498,88 @@ func processCellContent(content string) string {
469498
// Escape angle bracket placeholders
470499
content = escapeAngleBracketPlaceholders(content)
471500

501+
// Wrap technical patterns in backticks for code formatting
502+
content = wrapTechnicalPatternsInBackticks(content)
503+
472504
// Collapse all whitespace (including newlines) into single spaces for MDX compatibility
473505
// This prevents parsing errors with multi-line content in <td> tags
474506
content = strings.Join(strings.Fields(content), " ")
475507

476508
return content
477509
}
478510

511+
// wrapTechnicalPatternsInBackticks wraps patterns like memory_{some,full}_{avg10,avg60,avg300} in backticks
512+
func wrapTechnicalPatternsInBackticks(content string) string {
513+
// Pattern: word characters, underscores, with {option1,option2,...} expansions
514+
// Examples: memory_{some,full}_{avg10,avg60,avg300,total}
515+
// Look for: starts with letter/underscore, contains {, }, commas, and underscores
516+
517+
result := ""
518+
i := 0
519+
for i < len(content) {
520+
// Skip if already in backticks
521+
if i > 0 && content[i-1] == '`' {
522+
result += string(content[i])
523+
i++
524+
continue
525+
}
526+
527+
// Check if we're at the start of a potential pattern
528+
// Pattern should start with a letter or underscore
529+
if (content[i] >= 'a' && content[i] <= 'z') ||
530+
(content[i] >= 'A' && content[i] <= 'Z') ||
531+
content[i] == '_' {
532+
533+
// Look ahead to see if this contains the technical pattern markers
534+
start := i
535+
hasUnderscore := false
536+
hasBraces := false
537+
hasComma := false
538+
539+
// Scan ahead to find the end of this potential pattern
540+
end := i
541+
for end < len(content) {
542+
ch := content[end]
543+
544+
// Pattern continues with alphanumeric, underscore, braces, comma
545+
if (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
546+
(ch >= '0' && ch <= '9') || ch == '_' ||
547+
ch == '{' || ch == '}' || ch == ',' {
548+
549+
if ch == '_' {
550+
hasUnderscore = true
551+
}
552+
if ch == '{' || ch == '}' {
553+
hasBraces = true
554+
}
555+
if ch == ',' {
556+
hasComma = true
557+
}
558+
end++
559+
} else {
560+
break
561+
}
562+
}
563+
564+
// If we found a pattern with underscores, braces, and commas, wrap it
565+
if end > start && hasUnderscore && hasBraces && hasComma {
566+
pattern := content[start:end]
567+
// Make sure it's not already wrapped in backticks
568+
if start == 0 || content[start-1] != '`' {
569+
result += "`" + pattern + "`"
570+
i = end
571+
continue
572+
}
573+
}
574+
}
575+
576+
result += string(content[i])
577+
i++
578+
}
579+
580+
return result
581+
}
582+
479583
// cleanLinkText removes [] prefix from link text and moves it to href
480584
func cleanLinkText(line string) string {
481585
result := ""
@@ -700,9 +804,30 @@ func main() {
700804

701805
fmt.Printf("Converting docs from %s to %s\n", srcDir, dstDir)
702806

703-
// Remove and recreate destination directory
704-
os.RemoveAll(dstDir)
705-
os.MkdirAll(dstDir, 0755)
807+
// Files to preserve during conversion (don't delete these)
808+
preserveFiles := map[string]bool{
809+
"overview.mdx": true,
810+
}
811+
812+
// Instead of removing entire directory, selectively remove only generated files
813+
// This preserves manually created files like overview.mdx
814+
if _, err := os.Stat(dstDir); err == nil {
815+
// Directory exists, remove only .mdx files that aren't in preserve list
816+
filepath.Walk(dstDir, func(path string, info os.FileInfo, err error) error {
817+
if err != nil || info.IsDir() {
818+
return nil
819+
}
820+
821+
filename := filepath.Base(path)
822+
if !preserveFiles[filename] && strings.HasSuffix(path, ".mdx") {
823+
os.Remove(path)
824+
}
825+
return nil
826+
})
827+
} else {
828+
// Directory doesn't exist, create it
829+
os.MkdirAll(dstDir, 0755)
830+
}
706831

707832
// Walk through source directory
708833
err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {

public/talos/v1.12/reference/configuration/block/existingvolumeconfig.mdx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,3 @@ MountSpec describes how the volume is mounted.
147147
</tr>
148148
</tbody>
149149
</table>
150-
151-
152-
153-
154-
155-
156-

public/talos/v1.12/reference/configuration/block/rawvolumeconfig.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,3 @@ EncryptionKeyTPMOptions represents the options for TPM-based key protection.
448448
</tr>
449449
</tbody>
450450
</table>
451-
452-
453-
454-
455-
456-
457-
458-
459-
460-
461-
462-
463-

public/talos/v1.12/reference/configuration/block/swapvolumeconfig.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,3 @@ EncryptionKeyTPMOptions represents the options for TPM-based key protection.
446446
</tr>
447447
</tbody>
448448
</table>
449-
450-
451-
452-
453-
454-
455-
456-
457-
458-
459-
460-
461-

public/talos/v1.12/reference/configuration/block/uservolumeconfig.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -591,16 +591,3 @@ EncryptionKeyTPMOptions represents the options for TPM-based key protection.
591591
</tr>
592592
</tbody>
593593
</table>
594-
595-
596-
597-
598-
599-
600-
601-
602-
603-
604-
605-
606-

public/talos/v1.12/reference/configuration/block/volumeconfig.mdx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,3 @@ EncryptionKeyTPMOptions represents the options for TPM-based key protection.
448448
</tr>
449449
</tbody>
450450
</table>
451-
452-
453-
454-
455-
456-
457-
458-
459-
460-
461-
462-
463-

public/talos/v1.12/reference/configuration/block/zswapconfig.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,3 @@ shrinkerEnabled: true # Enable the shrinker feature: kernel might move
4949
</tr>
5050
</tbody>
5151
</table>
52-
53-
54-
55-
56-

public/talos/v1.12/reference/configuration/cli.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ talosctl cluster create docker [flags]
253253
--config-patch-workers stringArray patch generated machineconfigs (applied to 'worker' type)
254254
--cpus-controlplanes string the share of CPUs as fraction for each control plane/VM (default "2.0")
255255
--cpus-workers string the share of CPUs as fraction for each worker/VM (default "2.0")
256-
-p, --exposed-ports string comma-separated list of ports/protocols to expose on init node. Ex -p {"<"}hostPort{">"}:{"<"}containerPort{">"}/<protocol (tcp or udp)>
256+
-p, --exposed-ports string comma-separated list of ports/protocols to expose on init node. Ex -p {"<"}hostPort{">"}:{"<"}containerPort{">"}/{"<"}protocol (tcp or udp){">"}
257257
-h, --help help for docker
258258
--host-ip string Host IP to forward exposed ports to (default "0.0.0.0")
259259
--image string the talos image to run (default "ghcr.io/siderolabs/talos:v1.12.0-beta.1")
@@ -649,7 +649,7 @@ talosctl config merge {"<"}from{">"} [flags]
649649
Generate a new client configuration file
650650

651651
```
652-
talosctl config new [<path>] [flags]
652+
talosctl config new [{"<"}path{">"}] [flags]
653653
```
654654

655655
### Options
@@ -1340,7 +1340,7 @@ talosctl etcd remove-member {"<"}member ID{">"} [flags]
13401340
Stream snapshot of the etcd node to the path.
13411341

13421342
```
1343-
talosctl etcd snapshot <path> [flags]
1343+
talosctl etcd snapshot {"<"}path{">"} [flags]
13441344
```
13451345

13461346
### Options
@@ -2692,7 +2692,7 @@ talosctl processes [flags]
26922692
Read a file on the machine
26932693

26942694
```
2695-
talosctl read <path> [flags]
2695+
talosctl read {"<"}path{">"} [flags]
26962696
```
26972697

26982698
### Options
@@ -3289,4 +3289,3 @@ A CLI for out-of-band management of Kubernetes nodes created by Talos
32893289
* [talosctl validate](#talosctl-validate) - Validate config
32903290
* [talosctl version](#talosctl-version) - Prints the version
32913291
* [talosctl wipe](#talosctl-wipe) - Wipe block device or volumes
3292-

public/talos/v1.12/reference/configuration/cri/registryauthconfig.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,3 @@ password: my-password # Username/password authentication.
6868
</tr>
6969
</tbody>
7070
</table>
71-
72-
73-
74-
75-

public/talos/v1.12/reference/configuration/cri/registrymirrorconfig.mdx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,3 @@ RegistryEndpoint defines a registry mirror endpoint.
9494
</tr>
9595
</tbody>
9696
</table>
97-
98-
99-
100-
101-
102-
103-

0 commit comments

Comments
 (0)