Skip to content

Commit 106f211

Browse files
fix(ui): limit Markdown rendering on RichInput (#6061)
- Added a new `useMarkdown` prop to RichInput for toggling between Markdown and HTML content. - Updated the `extensions` function to conditionally configure link support based on the `useMarkdown` prop. - Modified the content update logic to handle Markdown conversion when `useMarkdown` is enabled. - Adjusted initial content loading to respect the `useMarkdown` setting for proper content type detection.
1 parent 02813aa commit 106f211

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

packages/ui/src/ui-component/input/RichInput.jsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ const isHtmlContent = (content) => {
2323
}
2424

2525
// define your extension array
26-
const extensions = (availableNodesForVariable, availableState, acceptNodeOutputAsVariable, nodes, nodeData, isNodeInsideInteration) => [
26+
const extensions = (
27+
availableNodesForVariable,
28+
availableState,
29+
acceptNodeOutputAsVariable,
30+
nodes,
31+
nodeData,
32+
isNodeInsideInteration,
33+
useMarkdown
34+
) => [
2735
Markdown,
2836
StarterKit.configure({
29-
codeBlock: false
37+
codeBlock: false,
38+
...(!useMarkdown && { link: false })
3039
}),
3140
CustomMention.configure({
3241
HTMLAttributes: {
@@ -103,6 +112,7 @@ const StyledEditorContent = styled(EditorContent)(({ theme, rows, disabled, isDa
103112
}))
104113

105114
export const RichInput = ({ inputParam, value, nodes, edges, nodeId, onChange, disabled = false }) => {
115+
const useMarkdown = !!inputParam?.rows
106116
const customization = useSelector((state) => state.customization)
107117
const isDarkMode = customization.isDarkMode
108118
const [availableNodesForVariable, setAvailableNodesForVariable] = useState([])
@@ -135,15 +145,20 @@ export const RichInput = ({ inputParam, value, nodes, edges, nodeId, onChange, d
135145
inputParam?.acceptNodeOutputAsVariable,
136146
nodes,
137147
nodeData,
138-
isNodeInsideInteration
148+
isNodeInsideInteration,
149+
useMarkdown
139150
),
140151
Placeholder.configure({ placeholder: inputParam?.placeholder })
141152
],
142153
content: '',
143154
onUpdate: ({ editor }) => {
144-
try {
145-
onChange(editor.getMarkdown())
146-
} catch {
155+
if (useMarkdown) {
156+
try {
157+
onChange(editor.getMarkdown())
158+
} catch {
159+
onChange(editor.getHTML())
160+
}
161+
} else {
147162
onChange(editor.getHTML())
148163
}
149164
},
@@ -155,7 +170,7 @@ export const RichInput = ({ inputParam, value, nodes, edges, nodeId, onChange, d
155170
// Load initial content after editor is ready, detecting HTML vs markdown
156171
useEffect(() => {
157172
if (editor && value) {
158-
if (isHtmlContent(value)) {
173+
if (!useMarkdown || isHtmlContent(value)) {
159174
editor.commands.setContent(value)
160175
} else {
161176
editor.commands.setContent(value, { contentType: 'markdown' })

0 commit comments

Comments
 (0)