Skip to content

Commit e5b9509

Browse files
Fix editorial review breaking MDX builds (#695)
The editorial workflow was adding HTML comments (<!-- -->) to MDX files, but MDX requires JSX-style comments ({/* */}). Instead of converting the comment syntax, this removes the embedded comment entirely and extracts the summary via a delimiter that gets stripped from the final content. Fixes build errors like: "Unexpected character `!` (U+0021) before name" Co-authored-by: Rachel Lee Nabors <nearestnabors@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8a11d88 commit e5b9509

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

scripts/vale-editorial.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const MAX_FILES = 5;
4545
const MAX_AI_TOKENS = 8192;
4646
const OWNER = "ArcadeAI";
4747
const REPO = "docs";
48-
const EDITORIAL_COMMENT_REGEX = /<!-- Editorial: (.+?) -->/;
48+
const SUMMARY_DELIMITER = "---SUMMARY---";
4949
const CODE_FENCE_OPEN_REGEX = /^```(?:mdx?|markdown)?\n/;
5050
const CODE_FENCE_CLOSE_REGEX = /\n```$/;
5151
const HTTP_UNPROCESSABLE_ENTITY = 422;
@@ -254,11 +254,35 @@ ${content}
254254
If the doc already conforms to the style guide, return exactly: NO_CHANGES_NEEDED
255255
256256
If changes are needed to conform to the style guide:
257-
1. Return ONLY the revised markdown content, no explanations
257+
1. Return ONLY the revised markdown content, no explanations or comments
258258
2. Preserve all code blocks exactly as they are
259259
3. Preserve frontmatter exactly as it is
260-
4. Add a brief HTML comment at the top (after frontmatter) citing which style guide sections required changes:
261-
<!-- Editorial: [Style guide section] - [what was changed] -->`;
260+
4. After the content, add a delimiter line "---SUMMARY---" followed by a brief summary of which style guide sections required changes
261+
262+
Example format:
263+
[revised markdown content here]
264+
---SUMMARY---
265+
Voice and tone - Changed "we" references; Structure - Added intro line`;
266+
}
267+
268+
// Extract content and summary from AI response
269+
function extractContentAndSummary(rawResponse: string): {
270+
content: string;
271+
summary: string;
272+
} {
273+
const stripped = stripCodeFences(rawResponse);
274+
const delimiterIndex = stripped.lastIndexOf(SUMMARY_DELIMITER);
275+
276+
if (delimiterIndex === -1) {
277+
return { content: stripped, summary: "Structural improvements" };
278+
}
279+
280+
const content = stripped.slice(0, delimiterIndex).trim();
281+
const summary =
282+
stripped.slice(delimiterIndex + SUMMARY_DELIMITER.length).trim() ||
283+
"Structural improvements";
284+
285+
return { content, summary };
262286
}
263287

264288
// Get editorial suggestions from Anthropic
@@ -280,15 +304,14 @@ async function getEditorialFromAnthropic(
280304
return null;
281305
}
282306

283-
const revisedContent = stripCodeFences(textBlock.text);
307+
const rawResponse = textBlock.text;
284308

285-
if (revisedContent === "NO_CHANGES_NEEDED") {
309+
if (stripCodeFences(rawResponse) === "NO_CHANGES_NEEDED") {
286310
return null;
287311
}
288312

289-
// Extract summary from the HTML comment if present
290-
const commentMatch = revisedContent.match(EDITORIAL_COMMENT_REGEX);
291-
const summary = commentMatch ? commentMatch[1] : "Structural improvements";
313+
const { content: revisedContent, summary } =
314+
extractContentAndSummary(rawResponse);
292315

293316
return {
294317
filename,
@@ -312,17 +335,17 @@ async function getEditorialFromOpenAI(
312335
messages: [{ role: "user", content: prompt }],
313336
});
314337

315-
const rawContent = response.choices[0]?.message?.content;
316-
if (!rawContent) {
338+
const rawResponse = response.choices[0]?.message?.content;
339+
if (!rawResponse) {
317340
return null;
318341
}
319-
const revisedContent = stripCodeFences(rawContent);
320-
if (revisedContent === "NO_CHANGES_NEEDED") {
342+
343+
if (stripCodeFences(rawResponse) === "NO_CHANGES_NEEDED") {
321344
return null;
322345
}
323346

324-
const commentMatch = revisedContent.match(EDITORIAL_COMMENT_REGEX);
325-
const summary = commentMatch ? commentMatch[1] : "Structural improvements";
347+
const { content: revisedContent, summary } =
348+
extractContentAndSummary(rawResponse);
326349

327350
return {
328351
filename,

0 commit comments

Comments
 (0)