MCPcopy Index your code
hub / github.com/python/mypy / convert

Function convert

misc/gen_blog_post_html.py:77–157  ·  view source on GitHub ↗
(src: str)

Source from the content-addressed store, hash-verified

75
76
77def convert(src: str) -> str:
78 h = src
79
80 # Replace < and >.
81 h = re.sub(r"<", "&lt;", h)
82 h = re.sub(r">", "&gt;", h)
83
84 # Title
85 h = re.sub(r"^## (Mypy [0-9.]+)", r"<h1>\1 Released</h1>", h, flags=re.MULTILINE)
86
87 # Subheadings
88 h = re.sub(r"\n### ([A-Z`].*)\n", r"\n<h2>\1</h2>\n", h)
89
90 # Sub-subheadings
91 h = re.sub(r"\n\*\*([A-Z_`].*)\*\*\n", r"\n<h3>\1</h3>\n", h)
92 h = re.sub(r"\n`\*\*([A-Z_`].*)\*\*\n", r"\n<h3>`\1</h3>\n", h)
93
94 # Translate `**`
95 h = re.sub(r"`\*\*`", "<tt>**</tt>", h)
96
97 # Paragraphs
98 h = re.sub(r"\n\n([A-Z])", r"\n\n<p>\1", h)
99
100 # Bullet lists
101 h = format_lists(h)
102
103 # Code blocks
104 h = format_code(h)
105
106 # Code fragments
107 h = re.sub(r"``([^`]+)``", r"<tt>\1</tt>", h)
108 h = re.sub(r"`([^`]+)`", r"<tt>\1</tt>", h)
109
110 # Remove **** noise
111 h = re.sub(r"\*\*\*\*", "", h)
112
113 # Bold text
114 h = re.sub(r"\*\*([A-Za-z].*?)\*\*", r" <b>\1</b>", h)
115
116 # Emphasized text
117 h = re.sub(r" \*([A-Za-z].*?)\*", r" <i>\1</i>", h)
118
119 # Remove redundant PR links to avoid double links (they will be generated below)
120 h = re.sub(r"\[(#[0-9]+)\]\(https://github.com/python/mypy/pull/[0-9]+/?\)", r"\1", h)
121
122 # Issue and PR links
123 h = re.sub(r"\((#[0-9]+)\) +\(([^)]+)\)", r"(\2, \1)", h)
124 h = re.sub(
125 r"fixes #([0-9]+)",
126 r'fixes issue <a href="https://github.com/python/mypy/issues/\1">\1</a>',
127 h,
128 )
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)
132 h = re.sub(r"\) \(PR", ", PR", h)
133
134 # Markdown links

Callers 1

mainFunction · 0.85

Calls 2

format_listsFunction · 0.85
format_codeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…