mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Unindent list items in the changelog
I found out that GitHub Actions use pandoc version 2.9.2.1 which converts bullet points like this: echo ' * Item * Another item ' | pandoc --from=rst --to=gfm - Item - Another item Note that each item has two-space indent. Meanwhile, locally I've been testing this conversion using pandoc 3.5 which does not add any indent: echo ' * Item * Another item ' | pandoc --from=rst --to=gfm - Item - Another item This commit removes the indent and cleans up the how the replacements in rst and md text are performed.
This commit is contained in:
parent
aff43d8d62
commit
e9076ffb53
1 changed files with 22 additions and 23 deletions
|
|
@ -13,6 +13,7 @@ from typing import Callable
|
||||||
import click
|
import click
|
||||||
import tomli
|
import tomli
|
||||||
from packaging.version import Version, parse
|
from packaging.version import Version, parse
|
||||||
|
from typing_extensions import TypeAlias
|
||||||
|
|
||||||
BASE = Path(__file__).parent.parent.absolute()
|
BASE = Path(__file__).parent.parent.absolute()
|
||||||
PYPROJECT = BASE / "pyproject.toml"
|
PYPROJECT = BASE / "pyproject.toml"
|
||||||
|
|
@ -23,6 +24,19 @@ version_header = r"\d+\.\d+\.\d+ \([^)]+\)"
|
||||||
RST_LATEST_CHANGES = re.compile(
|
RST_LATEST_CHANGES = re.compile(
|
||||||
rf"{version_header}\n--+\s+(.+?)\n\n+{version_header}", re.DOTALL
|
rf"{version_header}\n--+\s+(.+?)\n\n+{version_header}", re.DOTALL
|
||||||
)
|
)
|
||||||
|
Replacement: TypeAlias = "tuple[str, str | Callable[[re.Match[str]], str]]"
|
||||||
|
RST_REPLACEMENTS: list[Replacement] = [
|
||||||
|
(r"(?<=[\s(])`([^`]+)`(?=[^_])", r"``\1``"), # ticks with verbatim ranges.
|
||||||
|
(r":bug:`(\d+)`", r":bug: (#\1)"), # Issue numbers.
|
||||||
|
(r":user:`(\w+)`", r"@\1"), # Users.
|
||||||
|
]
|
||||||
|
MD_REPLACEMENTS: list[Replacement] = [
|
||||||
|
(r"^ ( *- )", r"\1"), # remove list indentation
|
||||||
|
(r"^(\w.+?):$", r"### \1"), # make sections headers
|
||||||
|
(r"^- `/?plugins/(\w+)`:?", r"- Plugin **`\1`**:"), # highlight plugins
|
||||||
|
(r"^- `(\w+)-cmd`:?", r"- Command **`\1`**:"), # highlight commands
|
||||||
|
(r"### [^\n]+\n+(?=### )", ""), # remove empty sections
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def update_docs_config(text: str, new: Version) -> str:
|
def update_docs_config(text: str, new: Version) -> str:
|
||||||
|
|
@ -95,18 +109,10 @@ def bump_version(new: Version) -> None:
|
||||||
|
|
||||||
def rst2md(text: str) -> str:
|
def rst2md(text: str) -> str:
|
||||||
"""Use Pandoc to convert text from ReST to Markdown."""
|
"""Use Pandoc to convert text from ReST to Markdown."""
|
||||||
# Other backslashes with verbatim ranges.
|
|
||||||
rst = re.sub(r"(?<=[\s(])`([^`]+)`(?=[^_])", r"``\1``", text)
|
|
||||||
|
|
||||||
# Bug numbers.
|
|
||||||
rst = re.sub(r":bug:`(\d+)`", r":bug: (#\1)", rst)
|
|
||||||
|
|
||||||
# Users.
|
|
||||||
rst = re.sub(r":user:`(\w+)`", r"@\1", rst)
|
|
||||||
return (
|
return (
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
["/usr/bin/pandoc", "--from=rst", "--to=gfm", "--wrap=none"],
|
["pandoc", "--from=rst", "--to=gfm", "--wrap=none"],
|
||||||
input=rst.encode(),
|
input=text.encode(),
|
||||||
)
|
)
|
||||||
.decode()
|
.decode()
|
||||||
.strip()
|
.strip()
|
||||||
|
|
@ -115,25 +121,18 @@ def rst2md(text: str) -> str:
|
||||||
|
|
||||||
def changelog_as_markdown() -> str:
|
def changelog_as_markdown() -> str:
|
||||||
"""Get the latest changelog entry as hacked up Markdown."""
|
"""Get the latest changelog entry as hacked up Markdown."""
|
||||||
with CHANGELOG.open() as f:
|
contents = CHANGELOG.read_text()
|
||||||
contents = f.read()
|
|
||||||
|
|
||||||
m = RST_LATEST_CHANGES.search(contents)
|
m = RST_LATEST_CHANGES.search(contents)
|
||||||
rst = m.group(1) if m else ""
|
rst = m.group(1) if m else ""
|
||||||
|
|
||||||
# Convert with Pandoc.
|
for pattern, repl in RST_REPLACEMENTS:
|
||||||
|
rst = re.sub(pattern, repl, rst, flags=re.M)
|
||||||
|
|
||||||
md = rst2md(rst)
|
md = rst2md(rst)
|
||||||
|
|
||||||
# Make sections stand out
|
for pattern, repl in MD_REPLACEMENTS:
|
||||||
md = re.sub(r"^(\w.+?):$", r"### \1", md, flags=re.M)
|
md = re.sub(pattern, repl, md, flags=re.M)
|
||||||
|
|
||||||
# Highlight plugin names
|
|
||||||
md = re.sub(
|
|
||||||
r"^- `/?plugins/(\w+)`:?", r"- Plugin **`\1`**:", md, flags=re.M
|
|
||||||
)
|
|
||||||
|
|
||||||
# Highlights command names.
|
|
||||||
md = re.sub(r"^- `(\w+)-cmd`:?", r"- Command **`\1`**:", md, flags=re.M)
|
|
||||||
|
|
||||||
# sort list items alphabetically for each of the sections
|
# sort list items alphabetically for each of the sections
|
||||||
return MD_CHANGELOG_SECTION_LIST.sub(
|
return MD_CHANGELOG_SECTION_LIST.sub(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue