Skip to content

Commit a14fad5

Browse files
committed
fix(docs-i18n): preserve list marker structure
1 parent 6f22ef0 commit a14fad5

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎scripts/docs-i18n/doc_chunked_raw.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type docChunkStructure struct {
3636
tagCounts map[string]int
3737
headingLevels []int
3838
listShapes []markdownListShape
39+
listMarkerPrefixes []string
3940
inlineCodeSpans []string
4041
linkDestinations []string
4142
protectedLinkLabels []string
@@ -97,6 +98,9 @@ func validateDocBodyFencedLiterals(source, translated string) error {
9798
if !slices.Equal(sourceStructure.listShapes, translatedStructure.listShapes) {
9899
return fmt.Errorf("list structure mismatch: source=%v translated=%v", sourceStructure.listShapes, translatedStructure.listShapes)
99100
}
101+
if !slices.Equal(sourceStructure.listMarkerPrefixes, translatedStructure.listMarkerPrefixes) {
102+
return fmt.Errorf("list marker structure mismatch: source=%q translated=%q", sourceStructure.listMarkerPrefixes, translatedStructure.listMarkerPrefixes)
103+
}
100104
if !sameStringMultiset(sourceStructure.inlineCodeSpans, translatedStructure.inlineCodeSpans) {
101105
return fmt.Errorf("inline code mismatch: source=%d translated=%d", len(sourceStructure.inlineCodeSpans), len(translatedStructure.inlineCodeSpans))
102106
}
@@ -291,6 +295,9 @@ func validateDocChunkTranslation(source, translated string) error {
291295
if !slices.Equal(sourceStructure.listShapes, translatedStructure.listShapes) {
292296
return fmt.Errorf("list structure mismatch: source=%v translated=%v", sourceStructure.listShapes, translatedStructure.listShapes)
293297
}
298+
if !slices.Equal(sourceStructure.listMarkerPrefixes, translatedStructure.listMarkerPrefixes) {
299+
return fmt.Errorf("list marker structure mismatch: source=%q translated=%q", sourceStructure.listMarkerPrefixes, translatedStructure.listMarkerPrefixes)
300+
}
294301
if !sameStringMultiset(sourceStructure.inlineCodeSpans, translatedStructure.inlineCodeSpans) {
295302
return fmt.Errorf("inline code mismatch: source=%d translated=%d", len(sourceStructure.inlineCodeSpans), len(translatedStructure.inlineCodeSpans))
296303
}
@@ -497,6 +504,7 @@ func summarizeDocChunkStructure(text string) docChunkStructure {
497504
tagCounts: countsWithoutFence(counts),
498505
headingLevels: extractMarkdownHeadingLevels(text),
499506
listShapes: extractMarkdownListShapes(text),
507+
listMarkerPrefixes: extractMarkdownListMarkerPrefixes(text),
500508
inlineCodeSpans: extractMarkdownInlineCodeValues(text),
501509
linkDestinations: extractMarkdownLinkDestinations(text),
502510
protectedLinkLabels: extractProtectedMarkdownLinkLabels(text),

‎scripts/docs-i18n/doc_mode_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,31 @@ func TestValidateDocChunkTranslationRejectsNestedListMovedToDifferentParentItem(
708708
}
709709
}
710710

711+
func TestValidateDocBodyRejectsListIndentationChangeInsideComponent(t *testing.T) {
712+
t.Parallel()
713+
714+
source := "<Accordion title=\"Gateway options\">\n- `autoApproveCidrs`: optional allowlist.\n- `sshVerify`: enabled by default.\n- `gateway.tools.deny`: extra deny rules.\n</Accordion>\n"
715+
translated := "<Accordion title=\"Gateway options\">\n- `autoApproveCidrs`: optionale Zulassungsliste.\n - `sshVerify`: standardmäßig aktiviert.\n - `gateway.tools.deny`: zusätzliche Sperrregeln.\n</Accordion>\n"
716+
717+
err := validateDocBodyFencedLiterals(source, translated)
718+
if err == nil {
719+
t.Fatal("expected component-nested list indentation change to be rejected")
720+
}
721+
if !strings.Contains(err.Error(), "list marker structure mismatch") {
722+
t.Fatalf("expected list marker structure error, got %v", err)
723+
}
724+
}
725+
726+
func TestExtractMarkdownListMarkerPrefixesIgnoresFencedExamples(t *testing.T) {
727+
t.Parallel()
728+
729+
text := "- Real item\n\n```md\n - Example nested item\n```\n\n> 1. Quoted item\n"
730+
want := []string{"- ", "> 1. "}
731+
if got := extractMarkdownListMarkerPrefixes(text); !slices.Equal(got, want) {
732+
t.Fatalf("list marker prefixes mismatch\nwant: %q\ngot: %q", want, got)
733+
}
734+
}
735+
711736
func TestValidateDocChunkTranslationRejectsTranslatedInlineCode(t *testing.T) {
712737
t.Parallel()
713738

‎scripts/docs-i18n/masking.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ func maskMarkdownDocSyntax(text string, nextPlaceholder func() string, placehold
8787
inlineRanges = append(inlineRanges, protectedMarkdownLinkRanges(text)...)
8888
masked := maskByteRanges(text, inlineRanges, nextPlaceholder, placeholders, mapping)
8989

90+
return maskByteRanges(masked, markdownListMarkerRanges(masked), nextPlaceholder, placeholders, mapping)
91+
}
92+
93+
func markdownListMarkerRanges(text string) [][2]int {
9094
listRanges := make([][2]int, 0)
9195
fenceState := markdownLiteralFenceState{}
9296
offset := 0
93-
for _, line := range strings.SplitAfter(masked, "\n") {
97+
for _, line := range strings.SplitAfter(text, "\n") {
9498
insideFence := false
9599
if fenceState.delimiter != "" {
96100
if continuesMarkdownLiteralFenceContainer(line, fenceState) {
@@ -115,7 +119,16 @@ func maskMarkdownDocSyntax(text string, nextPlaceholder func() string, placehold
115119
}
116120
offset += len(line)
117121
}
118-
return maskByteRanges(masked, listRanges, nextPlaceholder, placeholders, mapping)
122+
return listRanges
123+
}
124+
125+
func extractMarkdownListMarkerPrefixes(text string) []string {
126+
ranges := markdownListMarkerRanges(text)
127+
prefixes := make([]string, 0, len(ranges))
128+
for _, span := range ranges {
129+
prefixes = append(prefixes, text[span[0]:span[1]])
130+
}
131+
return prefixes
119132
}
120133

121134
func protectedMarkdownLinkRanges(text string) [][2]int {

‎scripts/docs-i18n/util.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const (
1414
workflowVersion = 16
15-
promptVersion = 31
15+
promptVersion = 32
1616
docsI18nEngineName = "codex"
1717
envDocsI18nProvider = "OPENCLAW_DOCS_I18N_PROVIDER"
1818
envDocsI18nModel = "OPENCLAW_DOCS_I18N_MODEL"

0 commit comments

Comments
 (0)