Newline inside bold string breaks email parser

AI-generated summary

A bug has been reported where a newline within a bold string in HTML email content breaks the markdown parser in Discourse, causing incorrect rendering. The issue was observed in an email originally formatted as <b>@All, d</b><b>oes anyone have topics...</b>, which rendered as *@All, d**oes anyone have topics they would like to discuss on today's call?* — breaking the bold styling due to the newline. downey provided the raw email and rendered output, while elberet helped retrieve the post’s raw text via /raw/#{topic_id}/#{post_number} link, confirming the newline was present in the cooked result but not the original email. elberet noted this is a legitimate parser bug since markdown does not allow inline formatting (like bold or italic) to span across block boundaries — a design choice to avoid ambiguity between paragraphs and list items. cawas contrasted this with their own issue involving post length limits and editor rendering differences, clarifying this is purely a markdown parsing behavior triggered by newlines. The consensus is that while the parser’s behavior is intentional, the presence of the newline in the cooked output — despite not being in the raw email — indicates a flaw in the email-to-markdown conversion process.

For some reason, some funky HTML email (thanks, Outlook!) that was sent as follows:

<div><b>@All, d</b><b>o=
es anyone have topics they would like to discuss on today&#39;s call?</b></=
div>

Got rendered as:

If anyone would like the full source to troubleshoot, let me know.

Is that the cooked or the raw text of the post?

It reminds me a bit of @cawas’ markdown issue… perhaps the post cooker is failing in a weird way and returns the raw instead of raising an error?

1 Like

The HTML an excerpt from the raw incoming email.

The image is the rendered/cooked result. :smile:

Ok, then what’s the raw that resulted in that cooked result? :grin:
(To clarify: the raw text in the post, not the raw email.)

I’m not sure how to see that if the post hasn’t been edited. There’s no such option in the admin actions menu. Any ideas?

/raw/#{topic_id}/#{post_number}, e.g. https://meta.discourse.org/raw/27384/5 :slight_smile:

2 Likes

Thanks; more hidden valuable admin features! :confounded:

Raw output of that message shows just like the image excerpt above:

*@All, d**oes anyone have topics they would like to discuss on today's
call?*
1 Like

Oh, there’s a newline between today's and call, hence the markdown parser doesn’t apply the inline styling. I wonder how the newline got there since it’s not in the raw email text?

Anyway, looks like a legit bug in the email parser to me.

2 Likes

I think this is very different from my case. I believe my case is more related with some kind of overflow and the difference between the preview md renderer and the post md renderer… Also it happened after I’ve edited the email in, so it must not be directly related with the email renderer or HTML conversor… Although this is also not either one’s fault!

IMHO this is all a simple markdown issue, which I’m not sure if it’s by design. If it is intented to be like that, well, then it is indeed a problem with the HTML / email conversor.

So, if there is a new line the markdown renderer does break the formatting. You can try it right here, right now:

*for broken
example*

renders to:

for broken
example

while

*for working example*

renders to:

for working example

The only difference there is the break line before example.

Yes, it is. Here it’s a superfluous newline, in your case it’s something else, but at first glance both cases looked as if potentially valid markdown simply didn’t get cooked. :wink:

The markdown parser’s behavior is indeed by design. Each line is considered a block and inline-styles cannot span across blocks. This is because the inline parser cannot know whether the two lines will turn into a single paragraph or, for instance, two list items…

1 Like