ChatGPT 4 stuck in infinite loop generating code! ⚠️

ChatGPT-4 is always stuck in an infinite loop when I prompt it to modify this code: ####pastebin####/sdmazEh5

this is the resulting generated answer, stuck in an infinite loop:
####pastebin####/tVGAL8Pt

This is the prompt I used:

Hello Assistant,

I have a Python script that converts a markdown file into an HTML file. However, it has several issues that need to be addressed. Here are the issues:

  1. UTF-8 Rendering: UTF-8 characters in the source markdown are not correctly rendered in the output HTML file.
  2. Code Block Styling: The code text between ``` characters in the markdown file is not rendered in the HTML file with a light gray background.
  3. Syntax Highlighting: The same code is not displayed with the correct syntax highlighting. For example, “```markdown” should display the content with syntax highlighting for markdown markup code.
  4. PDF Output: The PDF output format option doesn’t work.
  5. Section Numbering: The headings and the document sections and entries numbers are not generated correctly and they appear as numbers inside square brackets in the output HTML file.
  6. TOC Linking: The TOC in the output HTML file does not work and does not link to each section and paragraph.

I would like you to modify the script to fix these issues. Additionally, I would like you to add the following features:

  1. Section Numbering: Add automatic numbering for sections and subsections in the markdown content.
  2. Code Block Styling: Add a specific style to code blocks in the HTML content, including a light gray background.
  3. Syntax Highlighting: Implement syntax highlighting for code blocks in the HTML content using the pygments library.
  4. Heading Styling: Add specific styling to headings in the HTML content, including color and border styling.
  5. PDF Output: Fix the issue with PDF output not working by using the pdfkit library to convert HTML content to PDF.
  6. TOC Linking: Fix the issue with the table of contents (TOC) in the HTML output not linking to each section and paragraph.
  7. UTF-8 Rendering: Ensure that UTF-8 characters in the source markdown are correctly rendered in the output HTML file.
  8. Heading Rendering: Modify the rendering of headings to include an id attribute, allowing for direct linking to specific sections in the HTML content.
  9. Markdown Output: Add the option to save the output file in markdown format, preserving all changes in a way that the markdown file will still be human editable.
  10. Argparse Options: Modify the argparse options so that the ‘–output_format’ parameter can accept only 3 values: html5, pdf, and markdown.
  11. Output Path: Change the output path to always be the input filename with “_modified” added at the end, followed by the file extension corresponding to the output format chosen.
  12. Graphic Style Decoration: Add a nicer graphic style decoration lines for the sections titles and heading when generating the output HTML5, using a green-themed palette based on the color #348B6B.
  13. Line Decoration Differentiation: Differentiate the line decoration of headings and titles by using a different line thickness for each heading level.

Please make these modifications with the minimum amount of changes to the original code. Here is the link to the original Python script: %%%%pastebin%%%%/sdmazEh5

I tried many changes, but it always ends stuck in an infinite loop. Any ideas?