nedbat / scriv

Changelog management tool
https://scriv.readthedocs.io
Apache License 2.0
260 stars 29 forks source link

Enable line un-wrapping of Markdown for GitHub releases #66

Open jwodder opened 2 years ago

jwodder commented 2 years ago

If the source for the entries in a Markdown changelog are wrapped to some number of characters, then when scriv uses them as the body of a GitHub release, GitHub will render the intra-paragraph newlines as hard line breaks, so that this:

- Foo all the bars, and make sure the gnusto is no longer cleesh.
  Fixes [#XXX](https://github.com/datalad/datalad-next/issues/XXX) via
  [PR #YYY](https://github.com/datalad/datalad-next/pull/YYY)
  (by [@GITHUBHANDLE](https://github.com/GITHUBHANDLE))

ends up looking like this:

Hideous!

I would thus like to ask whether it's possible for scriv to add in some sort of automatic line un-wrapping for Markdown changelogs when using them as GitHub release bodies. One possible implementation (I'm not sure if it would work) would be to send the Markdown through pandoc with the --wrap=none option. Alternatively, something like re.sub(r'(?<=\S)(\r?\n[ \t]+)*\r?\n[ \t]*(?=\S)', ' ', body) might work for 90%+ of cases.

nedbat commented 2 years ago

Is it possible to simply not wrap your original changelog fragments?

yarikoptic commented 2 years ago

Then it becomes one long line, harder to edit etc. And for scriv it is simply different behavior between rst (ok to consume wrapped) and markdown (not ok).

nedbat commented 2 years ago

Yes, it's one long line, so you use word wrapping in your editor. I guess I'm not sure why scriv needs to fiddle with the line wrapping. How do you edit Markdown files now so that the hard line endings aren't a problem? Or, if you have hard line endings, then how do they not become a problem when the text is on GitHub? For example, what about long commit messages?

yarikoptic commented 2 years ago

Dear @nedbat thanks for the quick responses. Now that I am at the keyboard let me expand on my previous reply to answer your questions/clarify the situation. As a sidenote, I think that we are dealing with a bug or peculiarity of how github reneders markdown of the itemized lists with wrapped items (pycharm is also funny - typically rewraps nicely unless previous line has 2 trailing white spaces which it takes as a signal to have clear newline there... I must read more on "markdown conventions"). But let's get back to scriv and use its already existing behavior:

I guess I'm not sure why scriv needs to fiddle with the line wrapping.

Well, the question is kind of back to you since it already does that for .rst - why does it fiddle with the line wrapping for .rst?

And with that we can come up with answers to rest of the comments/questions you had by simply looking at https://raw.githubusercontent.com/nedbat/scriv/main/CHANGELOG.rst and sample changelog snippets as in randomly chosen https://github.com/nedbat/scriv/commit/3fa23cedcebc6b60563342ad61abbe38e7efd939

So, even if there are ways and means to work with long lines, it is more cumbersome and you yourself do not do that for scriv changelog entries. That is why we were asking to establish similar behavior for .md fragments. As a result it would also adhere to the Principle of Least Surprise by having different behavior between .rst and .md input formats handling and how they would render on github.

nedbat commented 2 years ago

TBH, the re-wrapping for .rst is an accident: scriv uses pandoc to convert .rst to .md for GitHub releases, since GitHub will only accept markdown. In theory there's no need for pandoc to add .md changelogs to releases. I suppose we could explore using pandoc for .md->.md also, but I'd hate to require people to install pandoc if they are already writing markdown. And if they aren't required to install pandoc, then we have a condition to check? It sounds like it will be very messy.

yarikoptic commented 2 years ago

I see the reservation! May be it could become a config option?

yarikoptic commented 2 years ago

just for another little piece of motivation against one lines -- look at https://github.com/datalad/datalad/pull/7107/files#diff-4fd7661b8fcafe326f99613d1de1a7c9cd23e2f7456019eefc2f3bd3d18dd401R3 and think how it would be in 1 liner and suggest a recommendation for its change: would be more cumbersome. I really hope that there could be an option so we could simply rely on pandoc. An alternative for us might be then to add it to our release workflow to run pandoc on all those .md first ourselves before calling out to scriv combine, wdyt @jwodder ?

yarikoptic commented 2 years ago

FWIW, we can't do it "ourselves" since we do not want oneliners in CHANGELOG.md but want them only within github release notes since otherwise they look quite suboptimal, see e.g. https://github.com/datalad/datalad/releases/tag/0.17.9

yarikoptic commented 1 year ago

@nedbat so what about a config option to trigger consistent use of pandoc?

yarikoptic commented 1 year ago

@nedbat ping on this issue.