executablebooks / mdformat

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

Wrap also wraps table markup #393

Closed MattFriedman closed 1 year ago

MattFriedman commented 1 year ago

Describe the bug

context When I apply --wrap to a file, it also wraps table markup in a way that breaks the table. ex. mdformat HOWTO.md --wrap 80

expectation I expected the wrap function to skip the table markup.

bug But instead the table result can end up like this:

| ![nuc-front-sm.jpg](images%2Fnuc-front-sm.jpg) |
|:----------------------------------------------:| | *Compact Mini-computers* |

and the output will be mangled.

problem This is a problem if I want to wrap my markup syntax but still want my table markup to be formatted properly. Suggest perhaps a comment skip markup such that mdformat could skip certain areas of the document...

Reproduce the bug

  1. Create. document that is unwrapped and has markdown table formatting.
  2. apply a --wrap to the doc where the wrap limit is less than the width of the table markup

List your environment

any environment

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

hukkin commented 1 year ago

Thanks for the issue!

The table syntax is not included in CommonMark spec so mdformat doesn't support it by default. Have you tried to

pip install mdformat-tables

?

(which installs this plugin https://github.com/executablebooks/mdformat-tables/)

MattFriedman commented 1 year ago

I installed mdformat-tables and reran the format. In this case, the table format was preserved which is awesome.

As a user, I kind of expect this to "just work" in the 1st place. I wonder if there's a way to achieve this, or make it more obvious to the user that they'll need additional plugins in various cases?

hukkin commented 1 year ago

Thanks for the feedback. This is something that would be solved by https://github.com/executablebooks/mdformat/issues/332 so I think I want to revisit that issue.