Skip to content

Commit bfad9e1

Browse files
Fix [Sphinx] [Automation] Issue -> PR conversion of tables | Closes #210 (#228)
* Refactor: Rebase and cleanup. This branch has been rebased onto the latest upstream/main to integrate recent dependency fixes (spec.lock update) and fix CI failures. The history has been cleaned to contain only the changes relevant to this feature. * Remove uv.lock from this PR * Fix: remove duplicate normalize_md() definition.
1 parent 806bbfe commit bfad9e1

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.github/workflows/auto-pr-on-issue.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: Install uv
2727
uses: astral-sh/setup-uv@v6
2828

29+
- name: Install Pandoc
30+
uses: pandoc/actions/setup@v1
31+
2932
- name: Set up Git
3033
run: |
3134
git config --global user.email "[email protected]"

.github/workflows/snapshot-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
- name: Install uv
1919
uses: astral-sh/setup-uv@v6
2020

21+
- name: Install Pandoc
22+
uses: pandoc/actions/setup@v1
23+
2124
- name: Run snapshot tests
2225
run: |
2326
uv run python .github/auto-pr-tests/test_runner.py

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = ">=3.12,<3.13"
77
dependencies = [
88
"builder",
99
"tqdm",
10-
"m2r",
10+
"pypandoc",
1111
"sphinx>=8.2.3",
1212
"sphinx-autobuild>=2024.10.3",
1313
"sphinx-needs>=5.1.0",

scripts/auto-pr-helper.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from textwrap import dedent, indent
77

8-
from m2r import convert
8+
import pypandoc
99

1010
scriptpath = "../"
1111
script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -19,7 +19,39 @@
1919

2020

2121
def md_to_rst(markdown: str) -> str:
22-
return convert(markdown)
22+
return pypandoc.convert_text(
23+
markdown,
24+
'rst',
25+
format='markdown',
26+
extra_args=['--wrap=none']
27+
)
28+
29+
30+
def normalize_list_separation(text: str) -> str:
31+
"""
32+
Ensures every new list block is preceded by a blank line,
33+
required for robust parsing by Pandoc when targeting RST
34+
"""
35+
# Regex to identify any line that starts a Markdown list item (* or -)
36+
_list_item_re = re.compile(r"^[ \t]*[*-][ \t]+")
37+
38+
output_buffer = []
39+
for line in text.splitlines():
40+
is_item = bool(_list_item_re.match(line))
41+
42+
# Get the last line appended to the output buffer
43+
prev = output_buffer[-1] if output_buffer else ""
44+
45+
# Check if a blank line needs to be inserted before list
46+
# (Current is item) AND (Prev is not blank) AND (Prev is not an item)
47+
if is_item and prev.strip() and not _list_item_re.match(prev):
48+
# Insert a blank line to clearly separate the new list block
49+
output_buffer.append("")
50+
51+
output_buffer.append(line)
52+
53+
return "\n".join(output_buffer)
54+
2355

2456
def normalize_md(issue_body: str) -> str:
2557
"""
@@ -176,6 +208,7 @@ def format_code_block(code: str, lang: str = "rust") -> str:
176208

177209
issue_body = json_issue["body"]
178210
issue_body = normalize_md(issue_body)
211+
issue_body = normalize_list_separation(issue_body)
179212

180213
fields = extract_form_fields(issue_body)
181214
chapter = fields["chapter"]

0 commit comments

Comments
 (0)