Skip to content

Commit

Permalink
[misc] fix blog post generator quirks (#18601)
Browse files Browse the repository at this point in the history
While preparing the 1.15 release blog posts, I noticed a few quirks with
our maarkdown converter:

- We treat any `\n` followed by a capital letter as a new paragraph,
which can cause too many `<p>` tags to be inserted at times (a common
cause in this blog post was a line break followed by the word "PR").
- Using multiple consecutive backticks for an inline code section is
valid markdown (it's commonly used for strings where you need to include
single backticks, eg ``` ``a string with a single ` :)`` ```), but our
script was confused by this and generated lots of erroneous `<tt>`
sections where they didn't belong.
- Including a `#\d` in the middle of a word caused the script to assume
it was a PR that it should link. In this specific case, the changelog
contains several occurrences of `mypy_mypyc-wheels#<PR number>`, which
the script was stomping on.

This PR contains some minor tweaks for the blog post generation script
that attempt to address these quirks.
  • Loading branch information
wesleywright authored Feb 5, 2025
1 parent ac921ae commit e9a813c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions misc/gen_blog_post_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def convert(src: str) -> str:
h = re.sub(r"`\*\*`", "<tt>**</tt>", h)

# Paragraphs
h = re.sub(r"\n([A-Z])", r"\n<p>\1", h)
h = re.sub(r"\n\n([A-Z])", r"\n\n<p>\1", h)

# Bullet lists
h = format_lists(h)
Expand All @@ -104,6 +104,7 @@ def convert(src: str) -> str:
h = format_code(h)

# Code fragments
h = re.sub(r"``([^`]+)``", r"<tt>\1</tt>", h)
h = re.sub(r"`([^`]+)`", r"<tt>\1</tt>", h)

# Remove **** noise
Expand All @@ -125,7 +126,9 @@ def convert(src: str) -> str:
r'fixes issue <a href="https://github.com/python/mypy/issues/\1">\1</a>',
h,
)
h = re.sub(r"#([0-9]+)", r'PR <a href="https://github.com/python/mypy/pull/\1">\1</a>', h)
# Note the leading space to avoid stomping on strings that contain #\d in the middle (such as
# links to PRs in other repos)
h = re.sub(r" #([0-9]+)", r' PR <a href="https://github.com/python/mypy/pull/\1">\1</a>', h)
h = re.sub(r"\) \(PR", ", PR", h)

# Markdown links
Expand Down

0 comments on commit e9a813c

Please # to comment.