Skip to content

Commit 0adf2cb

Browse files
committed
parsing list addition for md => html links
1 parent 8bc3db5 commit 0adf2cb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/modules.py

+9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ def extract_codeblock(match):
134134

135135
# 2) Now do the normal Markdown parsing on whatever’s left (outside code blocks)
136136

137+
# Now handle Markdown links and convert them to HTML
138+
def replace_markdown_link(match):
139+
link_text = match.group(1) # The text to display
140+
url = match.group(2) # The URL
141+
return f'<a href="{html.escape(url)}">{html.escape(link_text)}</a>'
142+
143+
# Replace Markdown links [text](url) with HTML <a> tags
144+
text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', replace_markdown_link, text)
145+
137146
# Headings: only match at the start of lines (via ^) and multiline
138147
text = re.sub(r'^(######)\s+(.*)', r'➤ <b>\2</b>', text, flags=re.MULTILINE)
139148
text = re.sub(r'^(#####)\s+(.*)', r'➤ <b>\2</b>', text, flags=re.MULTILINE)

0 commit comments

Comments
 (0)