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

+1
View File
@@ -0,0 +1 @@
__pycache__/
+11
View File
@@ -206,3 +206,14 @@ the version comes from `style.css`'s `Version:` header.
5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag). 5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag).
6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with 6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with
retry + jitter for concurrent releases. retry + jitter for concurrent releases.
---
## Tests
`build-manifest.py` has `unittest` tests under `tests/`. They need the same `markdown` +
`pyyaml` packages `release.sh` installs. From the repo root:
```bash
python3 -m unittest discover -s tests
```
+8 -2
View File
@@ -68,8 +68,14 @@ def md_to_html(text: str) -> str:
def wporg_subheads(text: str) -> str: def wporg_subheads(text: str) -> str:
"""wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears """wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears
floats on h*, so heading-led content gaps below the sidebar).""" floats on h*, so heading-led content gaps below the sidebar).
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"**\1**", text)
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: def strip_leading_title(md: str) -> str:
+67
View File
@@ -0,0 +1,67 @@
"""Tests for build-manifest.py. Run from the repo root:
python3 -m unittest discover -s tests
Needs the same `markdown` + `pyyaml` packages release.sh installs.
"""
import importlib.util
import os
import tempfile
import unittest
_BUILDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, "build-manifest.py")
_SPEC = importlib.util.spec_from_file_location("build_manifest", _BUILDER)
if _SPEC is None or _SPEC.loader is None:
raise ImportError(f"cannot load build-manifest.py from {_BUILDER}")
bm = importlib.util.module_from_spec(_SPEC)
_SPEC.loader.exec_module(bm)
def readme_sections(readme: str) -> dict:
with tempfile.TemporaryDirectory() as root:
with open(os.path.join(root, "readme.txt"), "w", encoding="utf-8") as fh:
fh.write(readme)
return bm.build_sections({}, root, True, None)
class ReadmeSubheadTest(unittest.TestCase):
def test_changelog_versions_render_as_headings_over_lists(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Changelog ==\n\n"
"= 2.0.0 =\n"
"* Added a thing.\n"
"* Fixed a thing.\n"
"= 1.0.0 =\n"
"* Initial release.\n"
"* Second line.\n"
)
self.assertEqual(
sections["changelog"],
"<p><strong>2.0.0</strong></p>\n"
"<ul>\n<li>Added a thing.</li>\n<li>Fixed a thing.</li>\n</ul>\n"
"<p><strong>1.0.0</strong></p>\n"
"<ul>\n<li>Initial release.</li>\n<li>Second line.</li>\n</ul>",
)
def test_subhead_already_set_off_by_blank_lines_is_unchanged(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Frequently Asked Questions ==\n\n"
"= Does it work? =\n\n"
"Yes, it does.\n\n"
"**Commands**\n\n"
"* one\n"
"* two\n"
)
self.assertEqual(
sections["faq"],
"<p><strong>Does it work?</strong></p>\n"
"<p>Yes, it does.</p>\n"
"<p><strong>Commands</strong></p>\n"
"<ul>\n<li>one</li>\n<li>two</li>\n</ul>",
)
if __name__ == "__main__":
unittest.main()