telegramify-markdown icon indicating copy to clipboard operation
telegramify-markdown copied to clipboard

Code blocks sometimes added to split text

Open Ziyann opened this issue 7 months ago β€’ 4 comments

Sometimes, when a long text is converted using the telegramify function, a code block is added to the last chunk. It's hard to reproduce - I believe it happens when there are no empty lines in the text, and markdown formatting is used. Here is a reproducible case:

#!/usr/bin/env python3

import asyncio
import telegramify_markdown

async def main():
    test = await telegramify_markdown.telegramify(
        """OH. MY. GOOOOOOSH, ZIYAN! EHEHEHEHE! πŸ€£πŸ’–πŸ”₯
WHAT is this GLORIOUSLY CHAOTIC and UTTERLY CULTURED compilation you've blessed my eyes and ears with?! This is like... peak early 2000s visual novel energy, and I AM LIVING FOR IT! The art style is SO nostalgic, and the dialogue? THE DIALOGUE! It's like a masterclass in cheeky innuendos and just... unabashed horniness! I'm blushing a little, but also cackling! πŸ˜‚
Let's just dive right into the madness, shall we?
*   **"Save it for when you actually get some real boobs! A real rack has some volume, some weight, some..."** (Sumika, I'm guessing?) POOR GIRL! Starting strong with the classic flat-chest teasing! And that angry little tick mark on her forehead! Adorable savagery! πŸ’’
*   Then it cuts to: **Illicit Sexual Relations... PERMIT?!** πŸ“œ W-Wait, WHAT?! Is this an official document?! For *that*?! My mind is BLOWN! The stamps and everything! Only in an eroge, lmao! Sumika's shocked "PERMIT?!" is just perfect!
*   **"Very well... Takeru... would you like to bathe with me?"** (Meiya, looking all regal and serious in her turtleneck) KYAAAA! So direct! So cool! And the little heart in Takeru's name! She's not messing around! πŸ›€πŸ’œ
*   **"Takeru-chan, you're getting this hard over dumb ol' me?"** (Sumika again, in bed, looking all cute and flustered!) Eeeek! The self-awareness! The directness! The cute! πŸ₯°
*   **"Let us return to the topic at hand. Why are these women not wearing any clothing?!"** (Meiya, still composed, but asking the REAL questions!) πŸ˜‚ And she's got that poster behind her that says "SYNDROME" which is just... *chef's kiss* for the context!
*   **"All I know about how to treat women I learned from porno, and yet I'm somehow managing to pleasure her."** TAKERU, YOU ABSOLUTE LEGEND! That's... quite the educational background! And he's got Meiya surrounded by roses! The sheer audacity! 🌹🀣
*   **Chizuru: "May Takeru take things a little more seriously!" Takeru: "May Chizuru's boobs get a little bigger!"** THE DUALITY! Her prayer is so earnest, and his is just... pure Takeru! The crowd in the background makes it even funnier! πŸ™πŸˆ
*   **Kei: "...Wanna have sex?"** DEADPAN. STRAIGHT TO THE POINT. NO CHASER. Kei is my spirit animal sometimes. Those intense purple eyes! πŸ’œβœ¨
*   **Yuuko-sensei talking about experimental bombs and then immediately: "C-Cut it out, dude...! Your breasts are rubbing up against me!"** SENSEI! The tonal whiplash! And her sassy "You can use this desk as a bed. Don't worry, I'm sure it can take a good pounding." I CAN'T! She's iconic! The "I'm just really not into younger guys, I'm afraid. Do try to keep it in your pants, okay?" The SASS! The POWER! πŸ‘ πŸ”₯ And that lab coat over the form-fitting outfit? YES, PLEASE!
*   **Mikoto: "No, really! It feels like my breasts are getting bigger and bigger these days!"** The hopeful optimism! And the whole squad posing! So wholesome amidst the chaos!
*   **Meiya: "I can't believe you're playing so much you're getting eye strain. My little baby bird is growing into a beautiful gamer girl."** Aww, that's actually kinda sweet! Then it immediately cuts to more horny stuff, lmao!
*   **Kei: "...Wanna see my boobs?" Guy: *motorboats* "The titties... They're too soft!!"** THE SHEER WHIPLASH! The absolute *heavenly* expression on his face! This is ART! πŸ˜‚πŸ‘Œ
*   **"Oh, wow... Meiya's hair smells really nice..."** (Takeru in a mecha cockpit with her!) Even in a serious mecha scene, the thirst is real! Her blush is adorable!
*   **"Promise not to steal my underwear."** Kei, setting boundaries! Good for her!
*   **"You wanna be chained up? That your fetish?"** She's just asking the important questions to understand him better, right? πŸ˜‰
*   **"Whoa... He's got four girls after him all at once? Sounds like quite the chick magnet."** Understatement of the century, Takeru!
AND THE MUSIC! That high-energy, super catchy J-rock/J-pop track playing throughout just elevates the whole experience into a fever dream of glorious, early 2000s eroge goodness! 🎢🎸
This whole video is a masterpiece of "WTF did I just watch, and why do I love it so much?!" The character designs are SO distinctive, especially Meiya's amazing purple hair and Yuuko-sensei's whole vibe. Sumika's pink hair with those yellow bow-like things is super cute too!
It's just so unapologetically PERVERTED and FUNNY! This is that old-school otaku culture that's wild, a bit unhinged, and doesn't take itself too seriously. Thanks for unearthing this gem, Ziyan! You've got a real eye for... *ahem*... *cultured content*! πŸ˜‰ What was YOUR favorite line from this beautiful mess? Teehee! βœ¨πŸ’–""",
        max_word_count=4090
    )
    print(test)

# Run the async function
if __name__ == "__main__":
    asyncio.run(main())

Outputs:

[
  Text(content="OH\\. MY\\. GOOOOOOSH, ZIYAN\\! EHEHEHEHE\\! πŸ€£πŸ’–πŸ”₯\nWHAT is this GLORIOUSLY CHAOTIC and UTTERLY CULTURED compilation you've blessed my eyes and ears with?\\! This is like\\.\\.\\. peak early 2000s visual novel energy, and I AM LIVING FOR IT\\! The art style is SO nostalgic, and the dialogue? THE DIALOGUE\\! It's like a masterclass in cheeky innuendos and just\\.\\.\\. unabashed horniness\\! I'm blushing a little, but also cackling\\! πŸ˜‚\nLet's just dive right into the madness, shall we?\n", content_trace=ContentTrace(source_type='text', extra={}), content_type=<ContentTypes.TEXT: 'text'>),
  Text(content='⦁   _"Save it for when you actually get some real boobs\\! A real rack has some volume, some weight, some\\.\\.\\."_ \\(Sumika, I\'m guessing?\\) POOR GIRL\\! Starting strong with the classic flat\\-chest teasing\\! And that angry little tick mark on her forehead\\! Adorable savagery\\! πŸ’’\n⦁   Then it cuts to: _Illicit Sexual Relations\\.\\.\\. PERMIT?\\!_ πŸ“œ W\\-Wait, WHAT?\\! Is this an official document?\\! For _that_?\\! My mind is BLOWN\\! The stamps and everything\\! Only in an eroge, lmao\\! Sumika\'s shocked "PERMIT?\\!" is just perfect\\!\n⦁   _"Very well\\.\\.\\. Takeru\\.\\.\\. would you like to bathe with me?"_ \\(Meiya, looking all regal and serious in her turtleneck\\) KYAAAA\\! So direct\\! So cool\\! And the little heart in Takeru\'s name\\! She\'s not messing around\\! πŸ›€πŸ’œ\n⦁   _"Takeru\\-chan, you\'re getting this hard over dumb ol\' me?"_ \\(Sumika again, in bed, looking all cute and flustered\\!\\) Eeeek\\! The self\\-awareness\\! The directness\\! The cute\\! πŸ₯°\n⦁   _"Let us return to the topic at hand\\. Why are these women not wearing any clothing?\\!"_ \\(Meiya, still composed, but asking the REAL questions\\!\\) πŸ˜‚ And she\'s got that poster behind her that says "SYNDROME" which is just\\.\\.\\. _chef\'s kiss_ for the context\\!\n⦁   _"All I know about how to treat women I learned from porno, and yet I\'m somehow managing to pleasure her\\."_ TAKERU, YOU ABSOLUTE LEGEND\\! That\'s\\.\\.\\. quite the educational background\\! And he\'s got Meiya surrounded by roses\\! The sheer audacity\\! 🌹🀣\n⦁   _Chizuru: "May Takeru take things a little more seriously\\!" Takeru: "May Chizuru\'s boobs get a little bigger\\!"_ THE DUALITY\\! Her prayer is so earnest, and his is just\\.\\.\\. pure Takeru\\! The crowd in the background makes it even funnier\\! πŸ™πŸˆ\n⦁   _Kei: "\\.\\.\\.Wanna have sex?"_ DEADPAN\\. STRAIGHT TO THE POINT\\. NO CHASER\\. Kei is my spirit animal sometimes\\. Those intense purple eyes\\! πŸ’œβœ¨\n⦁   _Yuuko\\-sensei talking about experimental bombs and then immediately: "C\\-Cut it out, dude\\.\\.\\.\\! Your breasts are rubbing up against me\\!"_ SENSEI\\! The tonal whiplash\\! And her sassy "You can use this desk as a bed\\. Don\'t worry, I\'m sure it can take a good pounding\\." I CAN\'T\\! She\'s iconic\\! The "I\'m just really not into younger guys, I\'m afraid\\. Do try to keep it in your pants, okay?" The SASS\\! The POWER\\! πŸ‘ πŸ”₯ And that lab coat over the form\\-fitting outfit? YES, PLEASE\\!\n⦁   _Mikoto: "No, really\\! It feels like my breasts are getting bigger and bigger these days\\!"_ The hopeful optimism\\! And the whole squad posing\\! So wholesome amidst the chaos\\!\n⦁   _Meiya: "I can\'t believe you\'re playing so much you\'re getting eye strain\\. My little baby bird is growing into a beautiful gamer girl\\."_ Aww, that\'s actually kinda sweet\\! Then it immediately cuts to more horny stuff, lmao\\!\n⦁   _Kei: "\\.\\.\\.Wanna see my boobs?" Guy: _motorboats_ "The titties\\.\\.\\. They\'re too soft\\!\\!"_ THE SHEER WHIPLASH\\! The absolute _heavenly_ expression on his face\\! This is ART\\! πŸ˜‚πŸ‘Œ\n⦁   _"Oh, wow\\.\\.\\. Meiya\'s hair smells really nice\\.\\.\\."_ \\(Takeru in a mecha cockpit with her\\!\\) Even in a serious mecha scene, the thirst is real\\! Her blush is adorable\\!\n⦁   _"Promise not to steal my underwear\\."_ Kei, setting boundaries\\! Good for her\\!\n⦁   _"You wanna be chained up? That your fetish?"_ She\'s just asking the important questions to understand him better, right? πŸ˜‰\n⦁   _"Whoa\\.\\.\\. He\'s got four girls after him all at once? Sounds like quite the chick magnet\\."_ Understatement of the century, Takeru\\!\nAND THE MUSIC\\! That high\\-energy, super catchy J\\-rock/J\\-pop track playing throughout just elevates the whole experience into a fever dream of glorious, early 2000s eroge goodness\\! 🎢🎸\nThis whole video is a masterpiece of "WTF did I just watch, and why do I love it so much?\\!" The character designs are SO distinctive, especially Meiya\'s amazing purple hair and Yuuko\\-sensei\'s whole vibe\\. Sumika\'s pink hair with those yellow bow\\-like things is super cute too\\!\n', content_trace=ContentTrace(source_type='text', extra={}), content_type=<ContentTypes.TEXT: 'text'>),
  Text(content="```\nIt's just so unapologetically PERVERTED and FUNNY\\! This is that old\\-school otaku culture that's wild, a bit unhinged, and doesn't take itself too seriously\\. Thanks for unearthing this gem, Ziyan\\! You've got a real eye for\\.\\.\\. \\_ahem\\_\\.\\.\\. \\_cultured content\\_\\! πŸ˜‰ What was YOUR favorite line from this beautiful mess? Teehee\\! βœ¨πŸ’–\n\n```\n", content_trace=ContentTrace(source_type='text', extra={}), content_type=<ContentTypes.TEXT: 'text'>)
]

Note the last output chunk getting wrapped in a code block (```), even thought there was no formatting around that block in the input.

Other than the code block, the output is correctly formatted in Telegram.

Ziyann avatar May 29 '25 10:05 Ziyann

This is a rare error indeed. You can try disabling the latex parser

sudoskys avatar May 29 '25 13:05 sudoskys

https://github.com/sudoskys/telegramify-markdown/blob/main/src/telegramify_markdown/init.py#L108

By default, latex will detect and convert some matching lines. It may cause unexpected changes.

I will change this option to be off by default

sudoskys avatar May 29 '25 13:05 sudoskys

This is a rare error indeed. You can try disabling the latex parser

I tried adding latex_escape=False to the above code, but it didn't help with this. Good point though, I don't need latex parsing, so I'll still disable it just in case.

Ziyann avatar May 29 '25 13:05 Ziyann

I will take some time to check this issue. I'm quite busy recently. Thanks for your report.

sudoskys avatar May 30 '25 03:05 sudoskys