Code blocks sometimes added to split text
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.
This is a rare error indeed. You can try disabling the latex parser
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
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.
I will take some time to check this issue. I'm quite busy recently. Thanks for your report.