Less indentation

main
Bob Mottram 2024-07-15 20:15:39 +01:00
parent f3d985dfa7
commit 13378eebbe
1 changed files with 28 additions and 24 deletions

View File

@ -185,31 +185,35 @@ def _markdown_replace_links(markdown: str) -> str:
if ctr == 0: if ctr == 0:
ctr += 1 ctr += 1
continue continue
if '[' in sections_links[ctr - 1] and \
')' in link_section: if not ('[' in sections_links[ctr - 1] and
link_text = sections_links[ctr - 1].split('[')[-1] ')' in link_section):
link_url = link_section.split(')')[0] ctr += 1
replace_str = '[' + link_text + '](' + link_url + ')' continue
link_text = link_text.replace('`', '')
if '!' + replace_str in section_text: link_text = sections_links[ctr - 1].split('[')[-1]
link_url = link_section.split(')')[0]
replace_str = '[' + link_text + '](' + link_url + ')'
link_text = link_text.replace('`', '')
if '!' + replace_str in section_text:
html_link = \
'<img class="markdownImage" src="' + \
link_url + '" alt="' + link_text + '" />'
section_text = \
section_text.replace('!' + replace_str, html_link)
if replace_str in section_text:
if not link_url.startswith('#'):
# external link
html_link = \ html_link = \
'<img class="markdownImage" src="' + \ '<a href="' + link_url + '" target="_blank" ' + \
link_url + '" alt="' + link_text + '" />' 'rel="nofollow noopener noreferrer">' + \
section_text = \ link_text + '</a>'
section_text.replace('!' + replace_str, html_link) else:
if replace_str in section_text: # bookmark
if not link_url.startswith('#'): html_link = \
# external link '<a href="' + link_url + '">' + link_text + '</a>'
html_link = \ section_text = \
'<a href="' + link_url + '" target="_blank" ' + \ section_text.replace(replace_str, html_link)
'rel="nofollow noopener noreferrer">' + \
link_text + '</a>'
else:
# bookmark
html_link = \
'<a href="' + link_url + '">' + link_text + '</a>'
section_text = \
section_text.replace(replace_str, html_link)
ctr += 1 ctr += 1
result += section_text result += section_text
return result return result