Skip to content

Commit 6deb5af

Browse files
fix(markdown): broaden trailing-punct lookahead to all word characters
The right-flanking delimiter fix only checked for Korean after closing ** but the same issue occurs with digits and letters (e.g. **text:**1). Widen lookahead from (?=[가-힣]) to (?=[^\s\p{P}\p{S}]) to match the exact CommonMark failure condition. Generated with oh-my-agent Co-Authored-By: First Fluke <our.first.fluke@gmail.com>
1 parent f68800f commit 6deb5af

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

packages/markdown/src/preprocess.integration.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ describe("preprocessMarkdown integration", () => {
5757
);
5858
});
5959

60+
it("renders bold with trailing colon before digit as strong tags", () => {
61+
const input =
62+
"**보강된 주요 속성:**1. 할인 효과 적용 (심리적 가격): - 기존에는 판매가(15,000원)만 있었으나";
63+
64+
expect(renderMarkdown(preprocessMarkdown(input))).toBe(
65+
"<p><strong>보강된 주요 속성</strong>:1. 할인 효과 적용 (심리적 가격): - 기존에는 판매가(15,000원)만 있었으나</p>",
66+
);
67+
});
68+
6069
it("renders bold with space-trimmed trailing paren before Korean as strong tags", () => {
6170
const input =
6271
"**다른 디자인의 스타일을 수정하거나, 현재 디자인의 느낌을 완전히 바꿔볼까요? ** 원하시는 작업이 있다면 말씀해 주세요!";

packages/markdown/src/preprocess.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ describe("preprocessMarkdown", () => {
5252
expect(preprocessMarkdown("**주의:**사항을 확인하세요")).toBe("**주의**:사항을 확인하세요");
5353
});
5454

55+
it("moves colon outside bold markers when followed by digit", () => {
56+
expect(preprocessMarkdown("**보강된 주요 속성:**1. 할인 효과 적용")).toBe(
57+
"**보강된 주요 속성**:1. 할인 효과 적용",
58+
);
59+
});
60+
5561
it("does not add space after any bold text followed by Korean", () => {
5662
expect(preprocessMarkdown("**볼드텍스트**입니다")).toBe("**볼드텍스트**입니다");
5763
});

packages/markdown/src/preprocess.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* 1. Trim invalid inner spaces around bold text: `** text **` → `**text**`
77
* 2. Move quoted bold text outside markers when followed by Korean: `**'text'**에` → `'**text**'에`
88
* 3. Move double-quoted bold text outside markers when followed by Korean: `**"text"**에` → `"**text**"에`
9-
* 4. Move trailing punctuation outside bold markers when followed by Korean: `**text)**을` → `**text**)`을`
9+
* 4. Move trailing punctuation outside bold markers when followed by word char: `**text:**1` → `**text**:1`
1010
* 5. Tilde escaping to prevent accidental strikethrough: `~` → `\~`
1111
*/
1212
export function preprocessMarkdown(content: string): string {
@@ -27,10 +27,10 @@ export function preprocessMarkdown(content: string): string {
2727
// **"text"**에 -> "**text**"에
2828
processed = processed.replace(/\*\*"([^"]+)"\*\*(?=[-])/g, '"**$1**"');
2929

30-
// 4. Move trailing punctuation outside bold markers when followed by Korean text
31-
// Fixes CommonMark right-flanking delimiter: punct before closing ** + Korean after = no bold
32-
// **text(등))**Korean → **text(등)**))Korean
33-
processed = processed.replace(/\*\*([^*]+?)([)\]:;,.!?]+)\*\*(?=[-])/g, "**$1**$2");
30+
// 4. Move trailing punctuation outside bold markers when followed by word characters
31+
// Fixes CommonMark right-flanking delimiter: punct before closing ** + non-punct/non-space after = no bold
32+
// **text:**1. list → **text**:1. list | **text(등))**Korean → **text(등)**))Korean
33+
processed = processed.replace(/\*\*([^*]+?)([)\]:;,.!?]+)\*\*(?=[^\s\p{P}\p{S}])/gu, "**$1**$2");
3434

3535
// 5. Escape tildes to prevent accidental strikethrough
3636
processed = processed.replace(/~/g, "\\~");

0 commit comments

Comments
 (0)