Skip to content

Commit f4cf34e

Browse files
committed
feat: add handling for identical unspaces fences replacement
1 parent eb4384c commit f4cf34e

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

.changeset/angry-bugs-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
add handling for identical unspaces fences replacement

packages/cli/src/cli/loaders/mdx2/code-placeholder.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,38 @@ describe("MDX Code Placeholder Loader", () => {
222222
expect(pushed).toBe(md);
223223
});
224224

225+
it("handles identical code snippets correctly", async () => {
226+
const md = dedent`
227+
First paragraph:
228+
229+
\`\`\`shell
230+
echo "hello world"
231+
\`\`\`
232+
233+
Second paragraph:
234+
\`\`\`shell
235+
echo "hello world"
236+
\`\`\`
237+
`;
238+
const pulled = await loader.pull("en", md);
239+
const pushed = await loader.push("es", pulled);
240+
expect(pushed).toBe(
241+
dedent`
242+
First paragraph:
243+
244+
\`\`\`shell
245+
echo "hello world"
246+
\`\`\`
247+
248+
Second paragraph:
249+
250+
\`\`\`shell
251+
echo "hello world"
252+
\`\`\`
253+
`,
254+
);
255+
});
256+
225257
it("leaves incomplete fences untouched", async () => {
226258
const md = "```js\nno close";
227259
const pulled = await loader.pull("en", md);

packages/cli/src/cli/loaders/mdx2/code-placeholder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function ensureTrailingFenceNewline(_content: string) {
1919
const replacement = match.trim().startsWith(">")
2020
? match
2121
: `\n\n${match}\n\n`;
22-
content = content.replace(match, replacement);
23-
workingContent = workingContent.replace(match, "");
22+
content = content.replaceAll(match, replacement);
23+
workingContent = workingContent.replaceAll(match, "");
2424
found = true;
2525
}
2626
} while (found);

0 commit comments

Comments
 (0)