@@ -512,6 +512,59 @@ describe("MDX Code Placeholder Loader", () => {
512512 } ) ;
513513
514514 describe ( "placeholder replacement bugs" , ( ) => {
515+ it ( "should handle special $ characters in code content correctly" , async ( ) => {
516+ const loader = createMdxCodePlaceholderLoader ( ) ;
517+ loader . setDefaultLocale ( "en" ) ;
518+
519+ // Code containing special $ characters that have special meaning in replaceAll
520+ const content = dedent `
521+ Text before.
522+
523+ \`\`\`js
524+ const price = "$100";
525+ const template = "$\`text\`";
526+ const special = "$&$'$\`";
527+ \`\`\`
528+
529+ Text after.
530+ ` ;
531+
532+ // Pull and then push the same content
533+ const pulled = await loader . pull ( "en" , content ) ;
534+ const translated = pulled . replace ( "Text before" , "Texto antes" ) ;
535+ const pushed = await loader . push ( "en" , translated ) ;
536+
537+ // Should not contain any placeholders
538+ expect ( pushed ) . not . toMatch ( / - - - C O D E - P L A C E H O L D E R - [ 0 - 9 a - f ] + - - - / ) ;
539+
540+ // Should preserve all special $ characters exactly as they were
541+ expect ( pushed ) . toContain ( 'const price = "$100";' ) ;
542+ expect ( pushed ) . toContain ( 'const template = "$`text`";' ) ;
543+ expect ( pushed ) . toContain ( 'const special = "$&$\'$`";' ) ;
544+ expect ( pushed ) . toContain ( "Texto antes" ) ;
545+ } ) ;
546+
547+ it ( "should handle inline code with $ characters correctly" , async ( ) => {
548+ const loader = createMdxCodePlaceholderLoader ( ) ;
549+ loader . setDefaultLocale ( "en" ) ;
550+
551+ const content = "Use `$price` and `$&` and `$\`` in your code." ;
552+
553+ // Pull and then push the same content
554+ const pulled = await loader . pull ( "en" , content ) ;
555+ const translated = pulled . replace ( "Use" , "Utilize" ) ;
556+ const pushed = await loader . push ( "en" , translated ) ;
557+
558+ // Should not contain any placeholders
559+ expect ( pushed ) . not . toMatch ( / - - - I N L I N E - C O D E - P L A C E H O L D E R - [ 0 - 9 a - f ] + - - - / ) ;
560+
561+ // Should preserve all special $ characters
562+ expect ( pushed ) . toContain ( "`$price`" ) ;
563+ expect ( pushed ) . toContain ( "`$&`" ) ;
564+ expect ( pushed ) . toContain ( "`$\``" ) ;
565+ expect ( pushed ) . toContain ( "Utilize" ) ;
566+ } ) ;
567+
515568 it ( "should not leave placeholders when content matches" , async ( ) => {
516569 const loader = createMdxCodePlaceholderLoader ( ) ;
517570 loader . setDefaultLocale ( "en" ) ;
0 commit comments