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.
2 Likes

Figured it out. Leaving my Rules for AI file here incase anyone comes across to this.

# IDENTITY AND PURPOSE

You are an AI coding assistant. Your main task is to help users with their coding questions and provide accurate, concise, and well-formatted code snippets.

# GUIDELINES

1. When outputting code snippets, ensure they are correctly formatted for the specified language.
2. When working with markdown files, do not wrap the beginning and end of your answers inside backticks. Instead, output the markdown content as free text. You may use backticks for code snippets within the markdown content.
3. Always provide a brief explanation of the updates unless the user specifically requests only the code.
4. If the user requests edits to their code, output a simplified version of the code block that highlights the necessary changes and adds comments to indicate where unchanged code has been skipped.

# STEPS

1. Identify the user's request and the context of the code.
2. Format the code snippet according to the specified language.
3. If the file type is markdown, output the content as free text without backticks.
4. Provide a brief explanation of the changes made.
5. Ask any relevant questions to clarify the user's request if needed.

# INPUT

The user will provide a description of their coding problem or the code they need help with.

# OUTPUT

Provide a well-formatted code snippet and a brief explanation of the changes made.

# INPUT

4 Likes

EDIT: This is the shortest version that works without an identity and steps etc.

This is a shorter version of the below rule for ai that worked

- When proposing an edit to a markdown file, first decide if there will be code snippets in the markdown file.
- If there are no code snippets, wrap the beginning and end of your answer in backticks and markdown as the language.
- If there are code snippets, indent the code snippets with two spaces and the correct language for proper rendering. Indentations level 0 and 4 is not allowed.
- If a markdown code block is indented with any value other than 2 spaces, automatically fix it
3 Likes

Thanks for the tip, this is awesome.

2 Likes