Issue: Markdown Code Block Escaping Problem in Cursor Chat

Description

When working with markdown files containing code blocks that use three backticks followed by a language specification, the cursor chat output fails to escape and render the code properly. This issue occurs when the code block itself contains backticks.

Steps to Reproduce

  1. Create an empty markdown file with the following content:

    Some random text
    
        ```sh
        export KUBECONFIG=<path_to_kubeconfig>
        export AWS_ACCESS_KEY_ID=<aws_access_key_id>
        export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
        ```
    
  2. Select all and add to chat with Command + L and ask cursor to rephrase the random text.

Expected Behavior

The nested code block should be properly escaped and rendered within the markdown. So that it is readable and in a copy-friendly format.

Actual Behavior

The cursor chat output fails to escape the backticks in the nested code block, resulting in improper rendering.

Example Screenshot

Environment

Version: 0.36.1
VSCode Version: 1.89.1
Commit: 7d6bfec438c371e16f7de1d9fc6d00e3338ab8a0
Date: 2024-07-06T02:45:07.502Z
Electron: 28.2.8
ElectronBuildId: undefined
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.5.0

Additional Information

  • The issue has been raised before in here but since it has been almost a year, I wanted to create a new issue with steps to reproduce.