markdownfmt icon indicating copy to clipboard operation
markdownfmt copied to clipboard

Badges and separate lines in the same paragraph

Open anacrolix opened this issue 7 years ago • 6 comments

I ran this on some project READMEs, and one interesting case is what it does to the badges. When writing these out by hand, it's easy to put them on separate lines, without a blank line between them, which renders them in the same paragraph, and makes them easy to maintain. But the tool merges them to the same line, which doesn't seem desirable.

anacrolix avatar Oct 09 '17 00:10 anacrolix

I understand what you're referring to.

I can suggest two alternatives that would work:

  1. Have the badges on the same line, space separated. It's consistent with the rendering as HTML. It's what I do in most READMEs, including the one in this repository. Downside might be that they're harder to maintain, as you said, but I change badges infrequently.

  2. Put 2 spaces at the end of each line to preserve the trailing newline. Like this:

    [![Build Status](https://travis-ci.org/...)](https://travis-ci.org/...)<space><space>
    [![GoDoc](https://godoc.org/...)](https://godoc.org/...)<space><space>
    

    Where <space> is just a space ( ).

dmitshur avatar Oct 11 '17 03:10 dmitshur

Option 2 results in the badges on different lines. Is there a strong need to merge text in the same paragraph on different markdown lines?

anacrolix avatar Oct 11 '17 06:10 anacrolix

You're right, option 2 will give different behavior.

It had to be done in some way. I considered it for some time:

https://github.com/shurcooL/markdownfmt/blob/f9ece38f23b0150fcfaa82de98ec43ce0b98a83e/markdown/main.go#L456

But ended up choosing to go without EXTENSION_HARD_LINE_BREAK option.

It was mostly motivated by the desire to have manually wrapped text become automatically wrapped text, so that it would be readable even as you resize the width of your editor. E.g., this paragraph would become a normal paragraph instead of a narrow one.

Option 1 still works.

dmitshur avatar Oct 11 '17 06:10 dmitshur

Do you want to reconsider that extension or expose a command-line flag?

anacrolix avatar Oct 11 '17 10:10 anacrolix

I can reconsider the extension, but I won't be adding command-ling flags. I want to maintain the zero-configuration property of the formatting tool, just like gofmt.

It will take me a while to think about whether that extension is a good idea. If you'd like to have it sooner, I suggest you make a fork and apply the change there for your own needs. That would be helpful, because you could also provide feedback on how well it works in your experience.

dmitshur avatar Oct 12 '17 02:10 dmitshur

Thanks

anacrolix avatar Oct 12 '17 05:10 anacrolix