Skip to content

Commit 522ee12

Browse files
docs-botCopilotheiskr
authored
fix(translations): strip |2- block-scalar whitespace and join multi-line dangling headings (#61249)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
1 parent e6d6a89 commit 522ee12

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

src/languages/lib/correct-translation-content.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ export function correctTranslatedContentStrings(
7878
// measured across all eight translated languages.
7979
content = joinDanglingMarkers(content)
8080

81+
// YAML `|2-` block-scalar artifacts: some translated frontmatter fields
82+
// (typically `intro`) arrive with a spurious leading newline followed by
83+
// deep indentation when the translator wrote `field: |2-\n\n content`.
84+
// The YAML parser preserves the leading blank line and extra indentation
85+
// in the parsed string. Strip that leading whitespace when the English
86+
// source has no such prefix.
87+
if (content.startsWith('\n') && !englishContent.startsWith('\n')) {
88+
content = content.replace(/^\n[ \t]*/, '')
89+
}
90+
8191
// --- Per-language fixes (es, ja, pt, zh, ru, fr, ko, de) ---
8292

8393
if (context.code === 'es') {
@@ -2173,17 +2183,35 @@ function joinDanglingMarkers(content: string): string {
21732183
}
21742184
const nextContent = nextDeep[1]
21752185

2186+
// Consume additional deeply-indented continuation lines so multi-line
2187+
// wrapped headings/blockquotes/bold-opens collapse onto one line
2188+
// (e.g. `##\n {%if%}\n content`). Returns the concatenated
2189+
// continuation text and the new line index.
2190+
const consumeContinuations = (start: number): { extra: string; nextI: number } => {
2191+
let extra = ''
2192+
let j = start
2193+
while (j + 1 < lines.length) {
2194+
const cont = lines[j + 1].match(deepIndented)
2195+
if (!cont) break
2196+
extra += cont[1]
2197+
j++
2198+
}
2199+
return { extra, nextI: j }
2200+
}
2201+
21762202
const heading = line.match(headingOnly)
21772203
if (heading) {
2178-
out.push(`${heading[1]}${heading[2]} ${nextContent}`)
2179-
i++
2204+
const { extra, nextI } = consumeContinuations(i + 1)
2205+
out.push(`${heading[1]}${heading[2]} ${nextContent}${extra}`)
2206+
i = nextI
21802207
continue
21812208
}
21822209

21832210
const bq = line.match(blockquoteOnly)
21842211
if (bq) {
2185-
out.push(`${bq[1]} ${nextContent}`)
2186-
i++
2212+
const { extra, nextI } = consumeContinuations(i + 1)
2213+
out.push(`${bq[1]} ${nextContent}${extra}`)
2214+
i = nextI
21872215
continue
21882216
}
21892217

@@ -2196,8 +2224,9 @@ function joinDanglingMarkers(content: string): string {
21962224

21972225
const boldOpen = line.match(markerThenBoldOnly)
21982226
if (boldOpen) {
2199-
out.push(`${boldOpen[1]}**${nextContent}`)
2200-
i++
2227+
const { extra, nextI } = consumeContinuations(i + 1)
2228+
out.push(`${boldOpen[1]}**${nextContent}${extra}`)
2229+
i = nextI
22012230
continue
22022231
}
22032232

0 commit comments

Comments
 (0)