fix: keep readme.txt subheads off the lines around them

wporg_subheads() turned `= 0.5.0 =` into `**0.5.0**` with no blank line
after it. Python-Markdown won't let a list interrupt a paragraph, so each
version's `* ` items joined the heading's paragraph as literal text, and
nl2br put <br /> between them. Every changelog published through this
action rendered that way (mu-migration, manifest-updater,
em-event-submissions). A subhead with no blank line before it also joined
the previous version's last item.

The bold line now has a blank line on each side, so it stays its own
block, as wp.org's <h4> does. A subhead that already had blank lines
around it renders exactly as before.

Adds the repo's first tests (stdlib unittest, run with
`python3 -m unittest discover -s tests`) and ignores __pycache__/.
This commit is contained in:
Mike Mulligan committed 2026-10-01 07:52:01 -04:00
1 parent dca1a6a5a6
commit 57910d9c86
4 files changed
+87 -2

No files matched your search

+8 -2
View File
@@ -68,8 +68,14 @@ def md_to_html(text: str) -> str:
def wporg_subheads(text: str) -> str:
"""wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears
floats on h*, so heading-led content gaps below the sidebar)."""
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"**\1**", text)
floats on h*, so heading-led content gaps below the sidebar).
The bold line is set off by a blank line on each side so it stays its own
block, as wp.org's <h4> does. Python-Markdown won't let a list interrupt a
paragraph, so without the blank after it a `= 1.0 =` line's `* ` items became
literal text joined by nl2br's <br />; without the blank before it, a subhead
straight after a list joined that list's last item."""
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"\n**\1**\n", text)
def strip_leading_title(md: str) -> str: