', replace_link, text)
regex_exp = r']+)? href="([^"]+)"(?: [^>]+)?(?: title="([^"]+)")?(?: [^>]+)?>(.*?)'
return re.sub(regex_exp, replace_link, text)
def convert_img_to_markdown(text):
"""
Convert
tags to Markdown format
"""
def replace_image(match):
url = match.group(1)
if not url.startswith('http://') and not url.startswith('https://'):
url = 'https://' + url
alt_text = match.group(2) or ''
title = match.group(3) or ''
return f""
# Use a regular expression to match each
tag and call replace_image on each match
# pylint: disable=line-too-long
regex_exp = r'
]+)? src="([^"]+)"(?: [^>]+)?(?: alt="([^"]+)")?(?: [^>]+)?(?: title="([^"]+)")?(?: [^>]+)?/>'
return re.sub(regex_exp, replace_image, text)
def convert_p_to_markdown(text):
# Use a regular expression to match each tag and replace it with a Markdown paragraph
return re.sub(r'
]+)?>(.*?)
', r'\n\n\1\n\n', text)