From a6ff000ac82940230b74dced9203f9dca72e0bd8 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sat, 14 Sep 2024 06:26:03 -0400 Subject: [PATCH] Fix markdown spacing --- webview-ui/src/components/ChatRow.tsx | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/webview-ui/src/components/ChatRow.tsx b/webview-ui/src/components/ChatRow.tsx index 62b332a..1d9cb75 100644 --- a/webview-ui/src/components/ChatRow.tsx +++ b/webview-ui/src/components/ChatRow.tsx @@ -465,7 +465,7 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa {icon} {title} -
+
@@ -518,7 +518,7 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa {title}
)} -
+
@@ -618,7 +618,7 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa {icon} {title}
-
+
@@ -635,7 +635,7 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa {title} )} -
+
@@ -669,7 +669,7 @@ const Markdown = memo(({ markdown }: { markdown?: string }) => { // return `__\n\n${content}\n\n__` }) return ( -
+
{ style={{ ...style, margin: 0, - marginTop: 0, - marginBottom: 0, + marginTop: 10, + marginBottom: 10, whiteSpace: "pre-wrap", wordBreak: "break-word", overflowWrap: "anywhere", @@ -720,6 +720,20 @@ const Markdown = memo(({ markdown }: { markdown?: string }) => { /> ) }, + // pre always surrounds a code, and we custom handle code blocks below. Pre has some non-10 margin, while all other elements in markdown have a 10 top/bottom margin and the outer div has a -10 top/bottom margin to counteract this between chat rows. However we render markdown in a completion_result row so make sure to add padding as necessary when used within other rows. + pre(props) { + const { style, ...rest } = props + return ( +
+						)
+					},
 					// https://github.com/remarkjs/react-markdown?tab=readme-ov-file#use-custom-components-syntax-highlight
 					code(props) {
 						const { children, className, node, ...rest } = props