diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c18dd8d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__/
diff --git a/README.md b/README.md
index a2ab013..5e7d07b 100644
--- a/README.md
+++ b/README.md
@@ -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).
6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with
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
+```
diff --git a/build-manifest.py b/build-manifest.py
index b5e4ec4..b10f6b5 100644
--- a/build-manifest.py
+++ b/build-manifest.py
@@ -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
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
; 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:
diff --git a/tests/test_build_manifest.py b/tests/test_build_manifest.py
new file mode 100644
index 0000000..71268c3
--- /dev/null
+++ b/tests/test_build_manifest.py
@@ -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"],
+ "
2.0.0
\n"
+ "\n- Added a thing.
\n- Fixed a thing.
\n
\n"
+ "1.0.0
\n"
+ "\n- Initial release.
\n- Second line.
\n
",
+ )
+
+ 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"],
+ "Does it work?
\n"
+ "Yes, it does.
\n"
+ "Commands
\n"
+ "",
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()