Skip to content

Commit 0d4142a

Browse files
committed
feat: quoted fences
1 parent f4cf34e commit 0d4142a

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

.changeset/thin-days-wonder.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+
quoted fences

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ describe("MDX Code Placeholder Loader", () => {
254254
);
255255
});
256256

257+
it("handles fenced code blocks inside quotes correctly", async () => {
258+
const md = dedent`
259+
> Code snippet inside quote:
260+
>
261+
> \`\`\`shell
262+
> npx -y mucho@latest install
263+
> \`\`\`
264+
`;
265+
const pulled = await loader.pull("en", md);
266+
const pushed = await loader.push("es", pulled);
267+
expect(pushed).toBe(md);
268+
});
269+
257270
it("leaves incomplete fences untouched", async () => {
258271
const md = "```js\nno close";
259272
const pulled = await loader.pull("en", md);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ function extractCodePlaceholders(content: string): {
5353
for (const match of codeBlockMatches) {
5454
const codeBlock = match[0];
5555
const codeBlockHash = md5(codeBlock);
56-
const placeholderId = `---CODE_PLACEHOLDER_${codeBlockHash}---`;
56+
const placeholder = `---CODE_PLACEHOLDER_${codeBlockHash}---`;
5757

58-
codePlaceholders[placeholderId] = codeBlock;
59-
finalContent = finalContent.replace(codeBlock, placeholderId);
58+
codePlaceholders[placeholder] = codeBlock;
59+
60+
const replacement = codeBlock.trim().startsWith(">")
61+
? `> ${placeholder}`
62+
: `${placeholder}`;
63+
finalContent = finalContent.replace(codeBlock, replacement);
6064
}
6165

6266
return {
@@ -82,7 +86,10 @@ export default function createMdxCodePlaceholderLoader(): ILoader<
8286
for (const [placeholder, original] of Object.entries(
8387
response.codePlaceholders,
8488
)) {
85-
result = result.replaceAll(placeholder, original);
89+
const replacement = original.startsWith(">")
90+
? _.trimStart(original, "> ")
91+
: original;
92+
result = result.replaceAll(placeholder, replacement);
8693
}
8794

8895
return result;

0 commit comments

Comments
 (0)