executablebooks / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
437 stars 46 forks source link

Incorrect behaviour with `<br>` or `<br/>` #394

Closed gwpl closed 1 year ago

gwpl commented 1 year ago

Describe the bug

This

> A <br/>
> B <br/>
> C

becomes this:

> A <br/> B <br/> C

I use new lines for readability, and <br> or <br/> should be respected.

Reproduce the bug

try to format snippet above with mdformat 0.7.16

List your environment

No response

hoijui commented 1 year ago

I do not understand the problem ... <br/> in terms of Markdown is just an other word, so if you have short lines, and the wrapping method you chose is not keep, then I would consider this correct behavior.

gwpl commented 1 year ago

I apologize for confusion. I have bash alias mdformat --number --wrap 70 so I forgotten to mention that I use --wrap n flag. This flag is actually one of main reasons I use mdformat. However I would love it to respect <br> or <br/> at the end of lines as clear indicator that this end of line should be preserved and is intentional.

hoijui commented 1 year ago

I'd recommend to apply something like this:

sed -E -e 's|(<br/?>)([^\n])|\1\n\2|g'

hoijui commented 1 year ago

I can understand what you want, but I;d not consider this incorrect behavior. In many cases even, in Markdown, I would very much not want to be a newline after a <br>, e.g. in tables.

gwpl commented 1 year ago

I see that differentiating between contexts (i.e. different treatment for quotes and paragraphs, and different for tables) would introduce complexity into codebase of formatter.

Thank you for providing table example, I haven't thought about this one!

sanmai-NL commented 1 year ago

@gwpl Can this issue be closed then, perhaps?

gwpl commented 1 year ago

I see that there is no easy way to fix it to solve all potential users needs , so yes, we can close it.