# Fugly code block

**URL:** <https://forum.cursor.com/t/fugly-code-block/5975>\
**Category:** Bug Reports\
**Created:** [June 24, 2024, 9:27am UTC](https://forum.cursor.com/t/fugly-code-block/5975 "2024-06-24T09:27:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyck3333](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nyck3333](https://forum.cursor.com/u/nyck3333)\
**Post date:** [June 24, 2024, 9:27am UTC](https://forum.cursor.com/t/fugly-code-block/5975/1 "2024-06-24T09:27:06Z")

</div>

![image](https://us1.discourse-cdn.com/cursor1/original/2X/b/b11f4a50699a639fb970bd179b3655153694ede3.png)

---

<div class="post-metadata">

**Author:** ![nyck3333](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nyck3333](https://forum.cursor.com/u/nyck3333)\
**Post date:** [June 24, 2024, 9:32am UTC](https://forum.cursor.com/t/fugly-code-block/5975/2 "2024-06-24T09:32:59Z")

</div>

After 5 months it’s clunky as ever.

---

<div class="post-metadata">

**Author:** ![nyck3333](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nyck3333](https://forum.cursor.com/u/nyck3333)\
**Post date:** [June 24, 2024, 9:34am UTC](https://forum.cursor.com/t/fugly-code-block/5975/3 "2024-06-24T09:34:33Z")

</div>

![image](https://us1.discourse-cdn.com/cursor1/original/2X/d/da69ac61969b8d4f061f86f6bd79389e6714f905.png)

That is ugly.

Why not concatenate the code blocks?

---

<div class="post-metadata">

**Author:** ![amanrs](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/amanrs/32/105_2.png) [@amanrs](https://forum.cursor.com/u/amanrs)\
**Post date:** [June 25, 2024, 6:29pm UTC](https://forum.cursor.com/t/fugly-code-block/5975/4 "2024-06-25T18:29:05Z")

</div>

Could you do me a favor and the next time you see this copy the full chat response (bottom right of the response, there is a copy icon you can click) and paste it here

---

<div class="post-metadata">

**Author:** ![nyck3333](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nyck3333](https://forum.cursor.com/u/nyck3333)\
**Post date:** [June 25, 2024, 9:01pm UTC](https://forum.cursor.com/t/fugly-code-block/5975/5 "2024-06-25T21:01:02Z")

</div>

```auto
k, system_prompt, user_prompt, max_tokens=2048, temperature=0.0)

            if translated_chunk is None:
                raise RuntimeError("Translation failed. Terminating program.")
            
            translated_chunk_path = os.path.join(translated_chunk_output_dir, f"{base_filename}_translated_part{i + 1}.txt")
            with open(translated_chunk_path, 'w', encoding='utf-8') as file:
                file.write(translated_chunk)
            
            final_translated_content += translated_chunk + '\n\n'
        
        write_translated_chunks(final_translated_content.split('\n\n'), output_file)
        
        print(f"Chunk directory: {chunk_output_dir}")
        print(f"Translated chunk directory: {translated_chunk_output_dir}")
        print(f"Final translated file: {output_file}")
    except Exception as e:
        print(f"An error occurred during processing: {e}")
        raise

if __name__ == " __main__":
    parser = argparse.ArgumentParser(description="Translate a .txt file from Japanese to English using OpenAI API")
    parser.add_argument('-i', '--input_file', type=str, required=True, help="Path to the input .txt file")
    parser.add_argument('-o', '--output_dir', type=str, required=True, help="Directory to save the intermediate and translated .txt files")
    parser.add_argument('-p', '--prompt_file', type=str, required=True, help="Path to the prompt file")
    parser.add_argument('-f', '--output_file', type=str, required=True, help="Path to the final translated .txt file")
    parser.add_argument('-t', '--token_limit', type=int, default=800, help="Token limit for each chunk")
    args = parser.parse_args()

    main(args.input_file, args.output_dir, args.prompt_file, args.output_file, args.token_limit)

```

### Summary of Changes

- **New `txt_splitter.py`** : Created to handle reading, splitting, and writing `.txt` files based on a token limit.
- **Updated `openai_translator.py`** : Modified to use `txt_splitter.py` for handling `.txt` files, including splitting, translating, and writing the translated chunks.

By making these changes, the script should be able to process `.txt` files, split them into chunks, translate each chunk, and then write the translated chunks back to a `.txt` file.

```auto

```

---

<div class="post-metadata">

**Author:** ![nyck3333](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nyck3333](https://forum.cursor.com/u/nyck3333)\
**Post date:** [June 25, 2024, 9:02pm UTC](https://forum.cursor.com/t/fugly-code-block/5975/6 "2024-06-25T21:02:57Z")

</div>

That is actually reversed in the GUI like the backticks surround the comment and the code is written as text in the GUI.

 ![image](https://us1.discourse-cdn.com/cursor1/original/2X/1/12aeb461e7e805e0b157813c15ad44c75b6a1629.png)

Also, copying is going to take a lot of time since higher up each line of code that appears as text has its own copy icon next to it. That is from cicking the very bottom right one which I thought would get them all but only got that.

---

<div class="post-metadata">

**Author:** ![amanrs](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/amanrs/32/105_2.png) [@amanrs](https://forum.cursor.com/u/amanrs)\
**Post date:** [June 26, 2024, 12:39am UTC](https://forum.cursor.com/t/fugly-code-block/5975/7 "2024-06-26T00:39:58Z")

</div>

Do you see this icon in the bottom right of chat? It should let you copy the whole thing.

 ![Screen Shot 2024-06-25 at 5.39.44 PM](https://us1.discourse-cdn.com/cursor1/original/2X/d/d95fe6815ac622dde8cf7013958627eb87e05d93.png)

---

<div class="post-metadata">

**Author:** ![condor](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/condor/32/73148_2.png) [@condor](https://forum.cursor.com/u/condor)\
**Post date:** [January 28, 2025, 1:49pm UTC](https://forum.cursor.com/t/fugly-code-block/5975/8 "2025-01-28T13:49:21Z")

</div>

its very common that we have to output MD files and then if cursor LLMs try to add markdown blocks like mermaid or similar it breaks also the MD file output, is there a way to fix that?

---

<div class="post-metadata">

**Author:** ![danperks](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/danperks/32/19087_2.png) [@danperks](https://forum.cursor.com/u/danperks)\
**Post date:** [January 28, 2025, 10:59pm UTC](https://forum.cursor.com/t/fugly-code-block/5975/9 "2025-01-28T22:59:40Z")

</div>

Markdown output has been improved a lot over the last few updates!

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/99069_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [December 21, 2025, 8:57am UTC](https://forum.cursor.com/t/fugly-code-block/5975/10 "2025-12-21T08:57:59Z")

</div>

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.
