[PR #30392] fix: [xxx](xxx) render as xxx](xxx) #32799

Closed
opened 2026-02-21 20:52:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/30392

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #30402

  1. clean_processor.py - Fixed URL removal to preserve markdown links and images

The previous implementation only protected markdown image URLs (alt) during URL removal, which caused:

  • Regular markdown links (text) to have their URL part stripped
  • Link text (which might itself be a URL) to be removed

Fix:

  • Now protects both markdown links and images with placeholders before URL removal
  • Changed placeholder format from MARKDOWN_IMAGE_URL_N to generic MARKDOWN_PLACEHOLDER_N
  • Added tuple structure for placeholders: (link_type, text/url, url) to distinguish links from images
  • Changed URL regex from https?://[^\s)]+ to https?://\S+ for better matching
  • Restores links as text and images as alt after cleanup
  1. text_processing_utils.py - Preserve leading markdown links

Added check to prevent remove_leading_symbols() from stripping markdown links at the start of text:

markdown_link_pattern = r'^\[([^\]]+)\]\((https?://[^)]+)\)'
if re.match(markdown_link_pattern, text):
   return text

This ensures links like OpenAI at the beginning of text are preserved.

Screenshots

Before After
... ...

before

https://github.com/user-attachments/assets/c3a474ab-a995-48d6-9c35-6eb0b871b729

after

https://github.com/user-attachments/assets/9f50c7d5-9833-46c5-ad89-e1ae7f31da3b

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30392 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix #30402 1. clean_processor.py - Fixed URL removal to preserve markdown links and images The previous implementation only protected markdown image URLs (![alt](url)) during URL removal, which caused: - Regular markdown links ([text](url)) to have their URL part stripped - Link text (which might itself be a URL) to be removed Fix: - Now protects both markdown links and images with placeholders before URL removal - Changed placeholder format from __MARKDOWN_IMAGE_URL_N__ to generic __MARKDOWN_PLACEHOLDER_N__ - Added tuple structure for placeholders: (link_type, text/url, url) to distinguish links from images - Changed URL regex from https?://[^\s)]+ to https?://\S+ for better matching - Restores links as [text](url) and images as ![alt](url) after cleanup 2. text_processing_utils.py - Preserve leading markdown links Added check to prevent remove_leading_symbols() from stripping markdown links at the start of text: ```python markdown_link_pattern = r'^\[([^\]]+)\]\((https?://[^)]+)\)' if re.match(markdown_link_pattern, text): return text ``` This ensures links like [OpenAI](https://openai.com) at the beginning of text are preserved. ## Screenshots | Before | After | |--------|-------| | ... | ... | before https://github.com/user-attachments/assets/c3a474ab-a995-48d6-9c35-6eb0b871b729 after https://github.com/user-attachments/assets/9f50c7d5-9833-46c5-ad89-e1ae7f31da3b ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:06 -05:00
yindo closed this issue 2026-02-21 20:52:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32799