Convert GitHub markdown to MyST format. - PR URLs -> {pr}`NUMBER` - Issue URLs -> {issue}`NUMBER` - @mentions -> {user}`USERNAME` - Strips HTML comments - Ensures proper list spacing
(body: str)
| 216 | |
| 217 | |
| 218 | def convert_to_myst(body: str) -> str: |
| 219 | """ |
| 220 | Convert GitHub markdown to MyST format. |
| 221 | |
| 222 | - PR URLs -> {pr}`NUMBER` |
| 223 | - Issue URLs -> {issue}`NUMBER` |
| 224 | - @mentions -> {user}`USERNAME` |
| 225 | - Strips HTML comments |
| 226 | - Ensures proper list spacing |
| 227 | """ |
| 228 | lines = body.split("\n") |
| 229 | result = [] |
| 230 | prev_bullet = False |
| 231 | |
| 232 | for line in lines: |
| 233 | # Skip HTML comments |
| 234 | if line.strip().startswith("<!--") and line.strip().endswith("-->"): |
| 235 | continue |
| 236 | |
| 237 | # Convert URLs to extlinks |
| 238 | line = re.sub( |
| 239 | r"https://github\.com/ManimCommunity/manim/pull/(\d+)", |
| 240 | r"{pr}`\1`", |
| 241 | line, |
| 242 | ) |
| 243 | line = re.sub( |
| 244 | r"https://github\.com/ManimCommunity/manim/issues/(\d+)", |
| 245 | r"{issue}`\1`", |
| 246 | line, |
| 247 | ) |
| 248 | line = re.sub(r"@([a-zA-Z0-9_-]+)", r"{user}`\1`", line) |
| 249 | |
| 250 | if line.startswith("**Full Changelog**:"): |
| 251 | _, url = line.split(":", 1) |
| 252 | url = url.strip().replace("vmain", "main") |
| 253 | line = f"**Full Changelog**: [Compare view]({url})" |
| 254 | |
| 255 | # Handle list spacing |
| 256 | is_bullet = line.strip().startswith("*") and not line.strip().startswith("**") |
| 257 | if prev_bullet and not is_bullet and line.strip(): |
| 258 | result.append("") |
| 259 | |
| 260 | result.append(line) |
| 261 | prev_bullet = is_bullet |
| 262 | |
| 263 | return "\n".join(result) |
| 264 | |
| 265 | |
| 266 | def format_changelog( |
no test coverage detected