[PR #20648] fix(markdown): Ensure abbr: links render correctly in react-markdown v9+ #29454

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

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

State: closed
Merged: Yes


Fixes #16243

Summary

In the early Dify version 0.15.3 (using react-markdown: "^8.0.6"), custom URL schemes like next advice and advice rendered as interactive links as intended. However, when later Dify versions upgraded to React-Markdown v9+, stricter default URL filtering (a security improvement) inadvertently removed support for schemes like abbr:. Consequently, these links no longer render interactively, impacting user experience.

This commit introduces a customUrlTransform function, now strategically located in web/app/components/base/markdown/markdown-utils.ts for better code organization. This function is passed to the ReactMarkdown component's urlTransform prop.

The customUrlTransform function ensures that:

  • The custom 'abbr:' protocol is explicitly allowed, restoring its functionality.
  • Standard safe web protocols (http, https, mailto, xmpp, irc, ircs) continue to be permitted.
  • Page-local fragments (#), protocol-relative URLs (//), and all purely relative paths are correctly handled and allowed.
  • Other potentially unsafe or unsupported URL schemes are disallowed by returning undefined, prompting react-markdown to remove the link or href attribute.

This change restores the intended functionality for 'abbr:' links, allowing users to interact with them as designed, while maintaining robust URL handling and security for the Markdown rendering component. The solution is self-contained and does not rely on external dummy URLs for parsing, making it suitable for self-hosted deployments.

Screenshots

https://github.com/user-attachments/assets/6e41763c-7e80-4300-a84c-ea4480341a92

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. (自测已覆盖多种URL场景)
  • [] 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/20648 **State:** closed **Merged:** Yes --- Fixes #16243 ## Summary In the early Dify version 0.15.3 (using react-markdown: "^8.0.6"), custom URL schemes like [next advice](abbr:next%20advice) and [advice](abbr:advice) rendered as interactive links as intended. However, when later Dify versions upgraded to React-Markdown v9+, stricter default URL filtering (a security improvement) inadvertently removed support for schemes like abbr:. Consequently, these links no longer render interactively, impacting user experience. This commit introduces a `customUrlTransform` function, now strategically located in `web/app/components/base/markdown/markdown-utils.ts` for better code organization. This function is passed to the `ReactMarkdown` component's `urlTransform` prop. The `customUrlTransform` function ensures that: - The custom 'abbr:' protocol is explicitly allowed, restoring its functionality. - Standard safe web protocols (http, https, mailto, xmpp, irc, ircs) continue to be permitted. - Page-local fragments (#), protocol-relative URLs (//), and all purely relative paths are correctly handled and allowed. - Other potentially unsafe or unsupported URL schemes are disallowed by returning `undefined`, prompting `react-markdown` to remove the link or `href` attribute. This change restores the intended functionality for 'abbr:' links, allowing users to interact with them as designed, while maintaining robust URL handling and security for the Markdown rendering component. The solution is self-contained and does not rely on external dummy URLs for parsing, making it suitable for self-hosted deployments. ## Screenshots https://github.com/user-attachments/assets/6e41763c-7e80-4300-a84c-ea4480341a92 ## 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. *(自测已覆盖多种URL场景)* - [] I've updated the documentation accordingly. *(如果此更改不直接影响用户文档,则此项可能不适用,或指内部开发者文档)* - [] 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:45:36 -05:00
yindo closed this issue 2026-02-21 20:45:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29454