Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions datasources/utils/outline_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _extract_document_content(self, document_id: str) -> str:
if text_content:
# Clean up the text content
cleaned_content = self._clean_text_content(text_content)
cleaned_content = self._resolve_relative_urls(cleaned_content)
formatted_content += cleaned_content

return formatted_content
Expand Down Expand Up @@ -165,6 +166,26 @@ def _clean_text_content(self, text: str) -> str:

return cleaned

def _resolve_relative_urls(self, text: str) -> str:
"""
Rewrite root-relative markdown link/image URLs (e.g. attachment
redirects like "/api/attachments.redirect?id=...") to absolute
URLs pointing at the Outline workspace, since Dify has no
knowledge of the Outline host to resolve them against.

Args:
text: Markdown content that may contain relative URLs

Returns:
Markdown content with relative URLs rewritten to absolute URLs
"""
pattern = re.compile(r'(!?\[[^\]]*\]\()(/(?!/)[^\s)]*)')

def replace(match: re.Match) -> str:
return f"{match.group(1)}{self.client.workspace_url}{match.group(2)}"

return pattern.sub(replace, text)

def _format_outline_markdown(self, content: str) -> str:
"""
Convert Outline's content format to standard markdown if needed.
Expand Down