Skip to content

Commit 1c7ef68

Browse files
committed
added fallback differentiation to avoid recursion depth issues
1 parent 7e08acc commit 1c7ef68

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

confluence_markdown_exporter/confluence.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,23 +809,35 @@ def convert_sup(self, el: BeautifulSoup, text: str, parent_tags: list[str]) -> s
809809
def convert_a(self, el: BeautifulSoup, text: str, parent_tags: list[str]) -> str: # noqa: PLR0911
810810
if "user-mention" in str(el.get("class")):
811811
return self.convert_user_mention(el, text, parent_tags)
812+
812813
if "createpage.action" in str(el.get("href")) or "createlink" in str(el.get("class")):
813814
if fallback := BeautifulSoup(self.page.editor2, "html.parser").find(
814815
"a", string=text
815816
):
816-
return self.convert_a(fallback, text, parent_tags) # type: ignore -
817+
818+
fallback_href = fallback.get("href", "")
819+
fallback_class = fallback.get("class", [])
820+
821+
if( "createpage.action" not in str(fallback_href) and
822+
"createlink" not in str(fallback_class)):
823+
return self.convert_a(fallback, text, parent_tags) # type: ignore -
824+
817825
return f"[[{text}]]"
826+
818827
if "page" in str(el.get("data-linked-resource-type")):
819828
page_id = str(el.get("data-linked-resource-id", ""))
820829
if page_id and page_id != "null":
821830
return self.convert_page_link(int(page_id))
831+
822832
if "attachment" in str(el.get("data-linked-resource-type")):
823833
link = self.convert_attachment_link(el, text, parent_tags)
824834
# convert_attachment_link may return None if the attachment meta is incomplete
825835
return link or f"[{text}]({el.get('href')})"
836+
826837
if match := re.search(r"/wiki/.+?/pages/(\d+)", str(el.get("href", ""))):
827838
page_id = match.group(1)
828839
return self.convert_page_link(int(page_id))
840+
829841
if str(el.get("href", "")).startswith("#"):
830842
# Handle heading links
831843
return f"[{text}](#{sanitize_key(text, '-')})"

0 commit comments

Comments
 (0)