diff --git a/proxy/source/markdown_parser.py b/proxy/source/markdown_parser.py index af36aba2..1fa4de1e 100644 --- a/proxy/source/markdown_parser.py +++ b/proxy/source/markdown_parser.py @@ -9,7 +9,7 @@ # The supported tags are: # - URLs -# - Headers (atx-style, parses to a single level) +# - Headers (atx-style. Parsed into span blocks with font-size. Capped at 4 levels) # - Inline emphasis (bold, italics) # - Inline code @@ -21,17 +21,15 @@ ############################################################################# # text = """ # [This is a link](http://example.net/). - # Another inline link [here](http://example.net/). - -# # Header - -# ## Another header - -# *some italics* _more italics_ - -# **some bold** __more bold__ - +# One more link for good measure: http://example.net/ +# # Header 1 +# ## Header 2 +# ### Header 3 +# #### Header 4 +# ##### Header 5 - Capped Size +# *some italics* and _more italics_ +# **some bold** and __more bold__ # `code` # """ @@ -39,17 +37,15 @@ # print(result) # | This is a link. -# | # | Another inline link here. -# | -# |
code
@@ -58,22 +54,36 @@ def _convert_crlf(input_str: str) -> str:
def _parse_links(input_str: str) -> str:
+ input_str = re.sub(
+ r"\[(.+?)\]\((https?:\/\/[-a-zA-Z0-9._~:/?#@!$&()*+,;=%']+)\)",
+ r'\1',
+ input_str,
+ flags=re.MULTILINE|re.IGNORECASE,
+ )
return re.sub(
- r"\[([\w\W]+?)\]\(([\w\W]+?)\)",
- r'\1',
+ r"(?\1',
input_str,
- flags=re.MULTILINE,
+ flags=re.MULTILINE|re.IGNORECASE,
)
def _parse_headers(input_str: str) -> str:
- return re.sub(r"^#+ +([\w\W]+?)\n", r"\1
", l)
+ re.sub(r"`(.+?)`", r"\1
", l)
for l in input_str.splitlines()
)