rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
422 stars 78 forks source link

Retain formatting of text (ie \n \t characters) #88

Closed milesgranger closed 3 years ago

milesgranger commented 3 years ago

Describe the bug Formatting / new lines / tabs are not retained.

To Reproduce

>>> body = "First line\nNewline\n\tTabbed in"
>>> message = pymsteams.connectorcard("https://example.com/")
>>> message.title("Test message, formatting")
>>> message.text(body)
>>> message.send()
True
>>> 

Result: image

Expected behavior I would have expected new lines, and tabs to be retained. I have sometimes, a large blob of JSON I'd like to print out as YAML since that's easier on the eyes, but it ends up just as unreadable. I've tried alternate carriage returns such as \r\n with the same result.

Appreciate any pointers you might have if I'm simply doing something silly here.


Edit: I notice that there is some success with \r\n\r\n for new lines, but no luck with tabs; pretty sure this is outside the control of this project.

rveachkc commented 3 years ago

If I had to guess, you're probably fighting some default formatting done in Teams.

Have you tried using a multi line code block using the three backticks? https://support.microsoft.com/en-us/office/use-markdown-formatting-in-teams-4d10bd65-55e2-4b2d-a1f3-2bebdcd2c772

milesgranger commented 3 years ago

Must be the case, even with the multi-line code block, it is a code block, but it's the same result with all the new lines removed.

After playing some more and digging deeper into the docs, even the markdown seems like a small subset; I can't seem to even get more than two levels deep in a bullet list. Which is inline with their docs about \n\n to indent, but alas, I can at least separate the top level keys of JSON blobs by using .addFact so that's okay enough.

I suppose this is an API issue in the end.

Thanks for making this, overall it's a great lib, seems like a fair amount of API restrictions outside of your control.