How to Correctly Create Markdown Files Containing Code Blocks

@jpshack-at-palomar I preferred your output more because I believe having the file in a copy-friendly format is better than using rendered Markdown. However, I think the indentation for code blocks should be consistently set to 2 spaces (even if it’s currently 0 or 4) to adhere to syntactically correct Markdown and avoid issues with edits.

With your prompt, although generating files from scratch works good, editing files seems to not edit the existing indentation and causing rendering errors

My test md file if you want to try out

## Test Instructions

some text

```python
print("Hello, World!")
```

some text

  ```javascript
  console.log("Hello, World!");
  ```

some text

    ```bash
    echo "Hello, World!"
    ```

Your existing prompt with 4 spaces

Your prompt with 2 spaces

Revised rule I use forcing always 2 spaces even in edits

- 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

End result

2 Likes