Skip to content

Commit 7f17f6e

Browse files
authored
Normalize adding (and allowing missing) trailing newlines for READMEs. (#7110)
* Normalize adding (and allowing missing) trailing newlines for READMEs. * Ensure ending newline in renderer, rather than renderer and diff.
1 parent 74733d2 commit 7f17f6e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

.tools/readmes/render.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def render(self) -> RenderStatus:
304304
customs=customs,
305305
unsupported=unsupported,
306306
)
307+
self.readme_text += "\n" # Jinja is the worst and strips trailing new lines
307308
[text, errors] = expand_all_entities(self.readme_text, self.scanner.doc_gen.entities)
308309
if errors:
309310
raise errors
@@ -332,7 +333,11 @@ def write(self):
332333
def read_current(self):
333334
try:
334335
with self.readme_filename.open("r", encoding="utf-8") as f:
335-
return f.read()
336+
current = f.read()
337+
if current[-1] != "\n":
338+
# Ensure there's always an ending newline
339+
current += "\n"
340+
return current
336341
except FileNotFoundError:
337342
return ""
338343

0 commit comments

Comments
 (0)