Skip to content

Commit e8170be

Browse files
fix(discord): preserve underscores in compacted progress
1 parent fe66510 commit e8170be

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/channels/streaming.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,16 +860,22 @@ function removeUnbalancedInlineBackticks(value: string): string {
860860
return value.trimStart().startsWith("`") ? value.replaceAll("`", "'") : value.replaceAll("`", "");
861861
}
862862

863-
function removeUnbalancedLeadingItalics(value: string): string {
864-
const underscoreCount = Array.from(value).filter((char) => char === "_").length;
865-
if (underscoreCount % 2 === 0 || !value.trimStart().startsWith("_")) {
863+
function removeUnbalancedLeadingItalicMarker(value: string): string {
864+
const leadingItalicMatch = value.match(/^(\s*)_(?!_)(.*)$/su);
865+
if (!leadingItalicMatch) {
866866
return value;
867867
}
868-
return value.replaceAll("_", "");
868+
869+
const [, leadingWhitespace, detail] = leadingItalicMatch;
870+
const hasClosingItalicMarker = /_(?=\s|$|[.,;:!?])/u.test(detail);
871+
if (hasClosingItalicMarker) {
872+
return value;
873+
}
874+
return `${leadingWhitespace}${detail}`;
869875
}
870876

871877
function removeUnbalancedInlineMarkdown(value: string): string {
872-
return removeUnbalancedLeadingItalics(removeUnbalancedInlineBackticks(value));
878+
return removeUnbalancedLeadingItalicMarker(removeUnbalancedInlineBackticks(value));
873879
}
874880

875881
function compactPlainProgressLine(line: string, maxChars: number): string {

src/plugin-sdk/channel-streaming.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,38 @@ describe("channel-streaming", () => {
363363
).toBe("Checking whether the Discord progress draft keeps markdown…");
364364
});
365365

366+
it("preserves underscores inside truncated commentary after dropping the italic marker", () => {
367+
expect(
368+
formatChannelProgressDraftText({
369+
entry: { streaming: { progress: { label: false, maxLineChars: 52 } } },
370+
lines: [
371+
{
372+
kind: "item",
373+
text: "_Checking the test_name path before the Discord progress draft truncates._",
374+
label: "Commentary",
375+
prefix: false,
376+
},
377+
],
378+
}),
379+
).toBe("Checking the test_name path before the Discord…");
380+
});
381+
382+
it("keeps compacted commentary when a leading italic span still has a closer", () => {
383+
expect(
384+
formatChannelProgressDraftText({
385+
entry: { streaming: { progress: { label: false, maxLineChars: 52 } } },
386+
lines: [
387+
{
388+
kind: "item",
389+
text: "_Reviewed_ the Discord progress draft before continuing with follow-up verification.",
390+
label: "Commentary",
391+
prefix: false,
392+
},
393+
],
394+
}),
395+
).toBe("_Reviewed_ the Discord progress draft before…");
396+
});
397+
366398
it("honors configured progress draft line length and cuts prose on word boundaries", () => {
367399
expect(
368400
formatChannelProgressDraftText({

0 commit comments

Comments
 (0)