Skip to content

Commit f078faa

Browse files
authored
[misc] Properly format subheadings and code in gen_blog_post_html.py (#18311)
Our Changelog uses 3 number signs (#) for subheadings, not 4. This should generate proper `<h3>` in the blog post. Also, code blocks are generated with just `<pre>` tags. Let's also add `<code>` tags so we can potentially apply syntax highlighting with js like highlight.js in the future, if we want to. highlight.js detects `<pre><code> ... </code></pre>`. We can also put the language, but it detects it automatically: https://highlightjs.readthedocs.io/en/latest/readme.html#in-the-browser
1 parent aa91842 commit f078faa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

misc/gen_blog_post_html.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def format_code(h: str) -> str:
4646
indent = a[i].startswith(" ")
4747
if not indent:
4848
i += 1
49-
r.append("<pre>")
49+
r.append("<pre><code>")
5050
while i < len(a) and (
5151
(indent and a[i].startswith(" ")) or (not indent and not a[i].startswith("```"))
5252
):
@@ -56,7 +56,7 @@ def format_code(h: str) -> str:
5656
line = " " + line
5757
r.append(html.escape(line))
5858
i += 1
59-
r.append("</pre>")
59+
r.append("</code></pre>")
6060
if not indent and a[i].startswith("```"):
6161
i += 1
6262
else:
@@ -76,7 +76,7 @@ def convert(src: str) -> str:
7676
h = re.sub(r"^## (Mypy [0-9.]+)", r"<h1>\1 Released</h1>", h, flags=re.MULTILINE)
7777

7878
# Subheadings
79-
h = re.sub(r"\n#### ([A-Z`].*)\n", r"\n<h2>\1</h2>\n", h)
79+
h = re.sub(r"\n### ([A-Z`].*)\n", r"\n<h2>\1</h2>\n", h)
8080

8181
# Sub-subheadings
8282
h = re.sub(r"\n\*\*([A-Z_`].*)\*\*\n", r"\n<h3>\1</h3>\n", h)

0 commit comments

Comments
 (0)