Skip to content

Commit dcb119c

Browse files
committed
fix(cli): extra slash n for code fences
1 parent b72c18a commit dcb119c

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

.changeset/big-suns-remain.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+
extra slash n for code fences

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@ import { createLoader } from "../_utils";
33
import { md5 } from "../../utils/md5";
44
import _ from "lodash";
55

6-
const unindentedFenceRegex = /(?<!\n\n)```([\s\S]*?)```(?!\n\n)/g;
7-
const indentedFenceRegex = /```([\s\S]*?)```/g;
6+
const fenceRegex = /```([\s\S]*?)```/g;
87

98
function ensureTrailingFenceNewline(_content: string) {
109
let found = false;
1110
let content = _content;
11+
let workingContent = content;
1212

1313
do {
1414
found = false;
15-
const matches = content.match(unindentedFenceRegex);
15+
const matches = workingContent.match(fenceRegex);
1616
if (matches) {
1717
const match = matches[0];
1818
content = content.replace(match, `\n\n${match}\n\n`);
19+
workingContent = workingContent.replace(match, "");
1920
found = true;
2021
}
2122
} while (found);
2223

23-
content = _.chain(content).split("\n\n").filter(Boolean).join("\n\n").value();
24+
content = _.chain(content)
25+
.split("\n\n")
26+
.map((section) => section.trim())
27+
.filter(Boolean)
28+
.join("\n\n")
29+
.value();
2430

2531
return content;
2632
}
@@ -38,7 +44,7 @@ function extractCodePlaceholders(content: string): {
3844

3945
const codePlaceholders: Record<string, string> = {};
4046

41-
const codeBlockMatches = finalContent.matchAll(indentedFenceRegex);
47+
const codeBlockMatches = finalContent.matchAll(fenceRegex);
4248

4349
for (const match of codeBlockMatches) {
4450
const codeBlock = match[0];

0 commit comments

Comments
 (0)