Skip to content

Feat/Add Markdown support to RichInput with Edit/Source toggle#6021

Merged
HenryHengZJ merged 3 commits intomainfrom
feature/Markdown-Editor
Mar 20, 2026
Merged

Feat/Add Markdown support to RichInput with Edit/Source toggle#6021
HenryHengZJ merged 3 commits intomainfrom
feature/Markdown-Editor

Conversation

@HenryHengZJ
Copy link
Copy Markdown
Contributor

@HenryHengZJ HenryHengZJ commented Mar 19, 2026

Summary

Before

image image When verify from Langsmith, you can see the markdowns are escaped by Turndownservice with a backslash: image

After

image image image When verify from Langsmith, you can see the markdowns are sent correctly as it is: image

Backward Compatibility

  • Legacy HTML content is auto-detected and rendered correctly via TipTap's native HTML parsing
  • New content is stored as markdown, and naturally migrates old HTML on re-save

Test plan

  • Paste markdown with headings (###), lists (-), bold (**) into RichInput — verify no backslash escaping at runtime
  • Test legacy HTML content loads correctly in both inline editor and expanded dialog
  • Toggle between Edit and Source in expanded dialog — verify content syncs correctly
  • Test variable resolution {{nodeId.data.instance}} still works with markdown content
  • Test edge cases: HTML with <strong>, <table>, <a> tags are still converted properly by TurndownService

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@HenryHengZJ
Copy link
Copy Markdown
Contributor Author

/gemini review

@HenryHengZJ
Copy link
Copy Markdown
Contributor Author

cc @jocelynlin-wd @j-sanaa can you guys update the same for the agentflow package richeditor

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades Tiptap dependencies to 3.20.3 and introduces a new Markdown extension to enable markdown content handling. The core change involves modifying resolveVariables in buildAgentflow.ts to conditionally convert HTML to markdown using TurndownService only if HTML tags are detected, with disabled escaping to preserve markdown syntax. In the UI, ExpandRichInputDialog.jsx and RichInput.jsx are updated to support both HTML and markdown content, dynamically detecting the content type for rendering and saving. ExpandRichInputDialog.jsx also gains a new toggle to switch between 'preview' (rich text editor) and 'raw' (textarea for source markdown/HTML) view modes, along with a new StyledTextarea component for the raw view. Review comments highlight a potential issue with the heuristic HTML detection regex, which might lead to false positives, and point out possible bugs in useEffect hooks in both ExpandRichInputDialog.jsx and RichInput.jsx where inputValue and value respectively are used but not included in the dependency arrays, potentially causing stale content.

}
isSwitchingRef.current = false
}
}, [editor]) // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The useEffect responsible for loading content into the editor has [editor] as its dependency. However, inputValue is used within this effect but is not listed as a dependency. While the eslint-disable-line react-hooks/exhaustive-deps comment indicates awareness, this pattern can lead to subtle bugs where the effect does not re-run when inputValue changes, resulting in stale content being displayed in the editor. This is particularly relevant if inputValue can be updated by means other than the editor's onUpdate callback or handleViewModeChange.

If inputValue is expected to change and trigger a re-render of the editor's content, it should be included in the dependency array. If not, ensure that the current behavior is well-understood and doesn't lead to unexpected UI states.

@HenryHengZJ
Copy link
Copy Markdown
Contributor Author

cc @jocelynlin-wd @j-sanaa can you guys update the same for the agentflow package richeditor

hold on, there is issue with resolving variables

- Implemented a custom tokenizer for recognizing {{...}} syntax in Markdown.
- Added parsing and rendering functions to handle mentions in Markdown format.
- Enhanced the CustomMention component to support Markdown serialization and deserialization.
@HenryHengZJ
Copy link
Copy Markdown
Contributor Author

This commit resolve custom mention issue:

Previously

When we change to Source, it resolved into specific format:
image

This causes backend not able to catch the double curly brackets, hence unable to get the actual value.

After:

image image

This ensure we are able to catch the double curly brackets with regex and replace with the actual value from server.

RY-0597

This comment was marked as resolved.

RY-0597

This comment was marked as resolved.

@HenryHengZJ HenryHengZJ merged commit 5daf8a3 into main Mar 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pasting Markdown in Agentflows V2 editor escapes characters and sends corrupted prompt to LLM

3 participants