Skip to content

Losing first word of message with Markdown pre encoding #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wofka72 opened this issue Dec 17, 2020 · 4 comments · Fixed by #597
Closed

Losing first word of message with Markdown pre encoding #481

wofka72 opened this issue Dec 17, 2020 · 4 comments · Fixed by #597
Labels
bug Something is wrong with the framework good first issue A good place to start contributing to this project without going too deep.

Comments

@wofka72
Copy link

wofka72 commented Dec 17, 2020

UPD. See the comment below for real issue

=== Original issue text starts here ===

Context

  • Operating System: Ubuntu 18.04
  • Python Version: 3.8.0
  • aiogram version: 2.9.2
  • aiohttp version: 3.6.2
  • uvloop version (if installed): Not installed

Expected Behavior

Message sended with parse_mode=ParseMode.MARKDOWN and wrapped with ```-braces loses first line (text till linebreak) if it have more than one line.

Current Behavior

First line should be sent too.

Steps to Reproduce

from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.types import ParseMode, Message
from aiogram.utils import executor

bot = Bot(token="<your_token>")
dp = Dispatcher(bot)

@dp.message_handler()
async def echo_message(msg: Message):
    await bot.send_message(msg.from_user.id, "```123\n456```", parse_mode=ParseMode.MARKDOWN)

executor.start_polling(dp)

loses first line:
image

async def echo_message(msg: Message):
    await bot.send_message(msg.from_user.id, "```123```", parse_mode=ParseMode.MARKDOWN)

works well:
image

Possible workaround before fix

  1. Adding extra linebreak to the beginning of message.
await bot.send_message(msg.from_user.id, "```\n123\n456```", parse_mode=ParseMode.MARKDOWN)

image

  1. Using HTML encoding.
await bot.send_message(msg.from_user.id, "<pre>123\n456</pre>", parse_mode=ParseMode.HTML)
@wofka72 wofka72 changed the title Losing first line of message with Markdown pre encoding Losing first word of message with Markdown pre encoding Dec 17, 2020
@evgfilim1
Copy link
Contributor

Hello and thanks for your report. However, it is upstream feature for specifying language in code block (like it is in GitHub).

Screenshot from Bot API documentation (picture is clickable):
image

@evgfilim1 evgfilim1 added invalid This doesn't seem right upstream Something not on our side labels Dec 17, 2020
@evgfilim1 evgfilim1 removed the invalid This doesn't seem right label Dec 17, 2020
@wofka72
Copy link
Author

wofka72 commented Dec 17, 2020

Method pre of aiogram.utils.text_decoration.MarkdownDecoration class just wraps text with tripple-quotes ```.
And sending such messages omits first word too.

from aiogram.utils.markdown import markdown_decoration as markdown  # use the object of class specified above
await bot.send_message(msg.from_user.id, markdown.pre("Answer: 42"), parse_mode=ParseMode.MARKDOWN)

image

I trapped little bit to this type of behaviour. I think that it could be strange and not obvious for new users. And on the other side it's small and some code could consider this behaviour. So I think that it shouldn't be changed on this stage of the project.
Just writing here about this feature :)

@evgfilim1
Copy link
Contributor

And sending such messages omits first word too.

Oh, now it looks like a small bug in our side. I'll reopen this issue and update the description. Thanks for clarification, @wofka72.

@evgfilim1 evgfilim1 reopened this Dec 17, 2020
@evgfilim1 evgfilim1 added bug Something is wrong with the framework good first issue A good place to start contributing to this project without going too deep. labels Dec 17, 2020
@p82o
Copy link

p82o commented Jun 4, 2021

label upstream can be removed because of #597

@evgfilim1 evgfilim1 removed the upstream Something not on our side label Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong with the framework good first issue A good place to start contributing to this project without going too deep.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants