@@ -207,7 +207,8 @@ function closeInlineMarkersLinear(line: string): string {
207207 // Count markers by scanning
208208 let asteriskCount = 0
209209 let underscoreCount = 0
210- let tildeCount = 0 // Count individual tildes
210+ let doubleTildeCount = 0 // Count ~~ occurrences (GFM strikethrough delimiter)
211+ let singleTildeCount = 0 // Count standalone ~ (not part of ~~)
211212 let backtickCount = 0
212213 let dollarCount = 0 // Count $ for math
213214 let dollarPairCount = 0 // Count $$ pairs for block math
@@ -298,7 +299,12 @@ function closeInlineMarkersLinear(line: string): string {
298299 }
299300 }
300301 } else if ( ch === '~' ) {
301- tildeCount ++
302+ if ( i + 1 < len && line [ i + 1 ] === '~' ) {
303+ doubleTildeCount ++
304+ i ++ // Skip second tilde since we counted the pair
305+ } else {
306+ singleTildeCount ++
307+ }
302308 } else if ( ch === '`' ) {
303309 backtickCount ++
304310 } else if ( ch === '$' && prevCh !== '\\' ) {
@@ -489,19 +495,15 @@ function closeInlineMarkersLinear(line: string): string {
489495 }
490496 }
491497
492- // Check ~~ (strikethrough)
493- if ( ! closingSuffix && tildeCount >= 2 ) {
494- const remainder = tildeCount % 4
495- if ( remainder === 2 ) {
496- // Two tildes unclosed, close with ~~
497- closingSuffix = '~~'
498- if ( hasTrailingSpace ) shouldTrim = true
499- } else if ( remainder > 2 && remainder < 4 ) {
500- // Partial marker like ~~text~ (3 tildes), need 1 more
501- const needed = 4 - remainder
502- closingSuffix = '~' . repeat ( needed )
503- if ( hasTrailingSpace ) shouldTrim = true
504- }
498+ // Check ~~ (strikethrough) and ~ (single-tilde) separately so that paired
499+ // singles like ~Hello~ are left alone while ~~text and ~Hello both close.
500+ if ( ! closingSuffix && doubleTildeCount % 2 === 1 ) {
501+ // A trailing single ~ after an open ~~ is a partial closer (~~text~)
502+ closingSuffix = singleTildeCount === 1 ? '~' : '~~'
503+ if ( hasTrailingSpace ) shouldTrim = true
504+ } else if ( ! closingSuffix && singleTildeCount % 2 === 1 ) {
505+ closingSuffix = '~'
506+ if ( hasTrailingSpace ) shouldTrim = true
505507 }
506508
507509 // Check ` (code)
0 commit comments