Skip to content

Commit d31f165

Browse files
authored
Fix 'What's New' page formatting and generation (#464)
* Fix 'What's New' page formatting and generation Improves the RST conversion logic in 'fetch_releases.py' to correctly handle Markdown headers, code blocks, images, and HTML details tags. Also updates 'conf.py' to use 'sys.executable' for robust script execution. * Switch to m2r2 for Markdown to RST conversion Replaces custom manual parsing with m2r2 library for more robust Markdown to ReStructuredText conversion in 'fetch_releases.py'. Adds 'm2r2' to 'environment.yml' dependencies. * Add lxml-html-clean dependency Fixes ImportError: lxml.html.clean module is now a separate project. This is required by nbsphinx.
1 parent d764a1d commit d31f165

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

docs/_scripts/fetch_releases.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
Dynamically build what's new page based on github releases
33
"""
44

5-
import requests, re
5+
import re
66
from pathlib import Path
77

8+
import requests
9+
from m2r2 import convert
10+
811
GITHUB_REPO = "ultraplot/ultraplot"
912
OUTPUT_RST = Path("whats_new.rst")
1013

@@ -14,21 +17,10 @@
1417

1518
def format_release_body(text):
1619
"""Formats GitHub release notes for better RST readability."""
17-
lines = text.strip().split("\n")
18-
formatted = []
19-
20-
for line in lines:
21-
line = line.strip()
22-
23-
# Convert Markdown ## Headers to RST H2
24-
if line.startswith("## "):
25-
title = line[3:].strip() # Remove "## " from start
26-
formatted.append(f"{title}\n{'~' * len(title)}\n") # RST H2 Format
27-
else:
28-
formatted.append(line)
20+
# Convert Markdown to RST using m2r2
21+
formatted_text = convert(text)
2922

3023
# Convert PR references (remove "by @user in ..." but keep the link)
31-
formatted_text = "\n".join(formatted)
3224
formatted_text = re.sub(
3325
r" by @\w+ in (https://github.com/[^\s]+)", r" (\1)", formatted_text
3426
)

docs/conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
# -- Imports and paths --------------------------------------------------------------
1313

1414
# Import statements
15-
import os
16-
import sys
1715
import datetime
16+
import os
1817
import subprocess
19-
from pathlib import Path
18+
import sys
2019

2120
# Surpress warnings from cartopy when downloading data inside docs env
2221
import warnings
22+
from pathlib import Path
2323

2424
try:
2525
from cartopy.io import DownloadWarning
@@ -38,6 +38,7 @@
3838
if not hasattr(sphinx.util, "console"):
3939
# Create a compatibility layer
4040
import sys
41+
4142
import sphinx.util
4243
from sphinx.util import logging
4344

@@ -54,7 +55,7 @@ def __getattr__(self, name):
5455
# Build what's news page from github releases
5556
from subprocess import run
5657

57-
run("python _scripts/fetch_releases.py".split(), check=False)
58+
run([sys.executable, "_scripts/fetch_releases.py"], check=False)
5859

5960
# Update path for sphinx-automodapi and sphinxext extension
6061
sys.path.append(os.path.abspath("."))
@@ -63,7 +64,6 @@ def __getattr__(self, name):
6364
# Print available system fonts
6465
from matplotlib.font_manager import fontManager
6566

66-
6767
# -- Project information -------------------------------------------------------
6868
# The basic info
6969
project = "UltraPlot"

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ dependencies:
3030
- networkx
3131
- pyarrow
3232
- cftime
33+
- m2r2
34+
- lxml-html-clean
3335
- pip:
3436
- git+https://github.com/ultraplot/UltraTheme.git

0 commit comments

Comments
 (0)