Adjust gitchangelog whitespace

Format the output to produce a nicer looking rst output, similar to the
former CHANGES file.
This commit is contained in:
Nicki Křížek 2024-07-17 14:58:01 +02:00
parent c2b23fa2de
commit 1c95eeeb3f
No known key found for this signature in database
GPG key ID: 01623B9B652A20A7

View file

@ -545,7 +545,7 @@ def indent(text, chars=" ", first=None):
return "\n".join([(chars + line).rstrip() for line in text.split("\n")])
def paragraph_wrap(text, regexp="\n\n"):
def paragraph_wrap(text, regexp="\n\n", separator="\n"):
r"""Wrap text by making sure that paragraph are separated correctly
>>> string = 'This is first paragraph which is quite long don\'t you \
@ -560,7 +560,7 @@ def paragraph_wrap(text, regexp="\n\n"):
"""
regexp = re.compile(regexp, re.MULTILINE)
return "\n".join(
return separator.join(
"\n".join(textwrap.wrap(paragraph.strip())) for paragraph in regexp.split(text)
).strip()
@ -1483,7 +1483,7 @@ def rest_py(data, opts={}):
"""Returns ReStructured Text changelog content from data"""
def rest_title(label, char="="):
return (label.strip() + "\n") + (char * len(label) + "\n")
return (label.strip() + "\n") + (char * len(label) + "\n\n")
def render_version(version):
title = (
@ -1500,7 +1500,7 @@ def rest_py(data, opts={}):
section_label = section["label"] if section.get("label", None) else "Other"
if not (section_label == "Other" and nb_sections == 1):
s += "\n" + rest_title(section_label, "~")
s += rest_title(section_label, "~")
for commit in section["commits"]:
s += render_commit(commit, opts)
@ -1518,14 +1518,16 @@ def rest_py(data, opts={}):
entry += "\n" + indent(commit["body"])
entry += "\n"
entry += "\n"
return entry
if data["title"]:
yield rest_title(data["title"], char="=") + "\n\n"
yield rest_title(data["title"], char="=") + "\n"
for version in data["versions"]:
if len(version["sections"]) > 0:
yield render_version(version) + "\n\n"
yield render_version(version) + "\n"
## formatter engines