Skip to content

Commit e9a813c

Browse files
authored
[misc] fix blog post generator quirks (#18601)
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.
1 parent ac921ae commit e9a813c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

misc/gen_blog_post_html.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def convert(src: str) -> str:
9595
h = re.sub(r"`\*\*`", "<tt>**</tt>", h)
9696

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

100100
# Bullet lists
101101
h = format_lists(h)
@@ -104,6 +104,7 @@ def convert(src: str) -> str:
104104
h = format_code(h)
105105

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

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

131134
# Markdown links

0 commit comments

Comments
 (0)