Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

Markdown rendering

Open notmd opened this issue 2 years ago • 4 comments

close #1350 #837

Update: Ready to review now

Lightmode

image

Darkmode

image

notmd avatar Feb 13 '23 14:02 notmd

@notmd thank you for solving this. The only test case that fails is ordered lists (1., 2., etc.) are not rendering the numbers. The line spacing is also really big still in message blocks.

Also, one thing that was discussed was to also render the Markdown when the user presses Review. Here is a diff that does this for your convenience:

Git diff
diff --git a/website/src/components/Tasks/CreateTask.tsx b/website/src/components/Tasks/CreateTask.tsx
index 448ad287..b28f5ad6 100644
--- a/website/src/components/Tasks/CreateTask.tsx
+++ b/website/src/components/Tasks/CreateTask.tsx
@@ -10,6 +10,7 @@ import { getTypeSafei18nKey } from "src/lib/i18n";
 import { TaskType } from "src/types/Task";
 import { CreateTaskReply } from "src/types/TaskResponses";
 import { CreateTaskType } from "src/types/Tasks";
+import RenderedMarkdown from "../Messages/RenderedMarkdown";
 
 export const CreateTask = ({
   task,
@@ -37,6 +38,11 @@ export const CreateTask = ({
     }
   };
 
+  let renderedMessage = <></>;
+  if (!isEditable) {
+    renderedMessage = <RenderedMarkdown markdown={inputText}></RenderedMarkdown>;
+  }
+
   return (
     <div data-cy="task" data-task-type="create-task">
       <TwoColumnsWithCards>
@@ -55,16 +61,19 @@ export const CreateTask = ({
                 {t(getTypeSafei18nKey(`tasks:${taskType.id}.instruction`))}
               </Text>
             )}
-            <TrackedTextarea
-              text={inputText}
-              onTextChange={textChangeHandler}
-              thresholds={{ low: 20, medium: 40, goal: 50 }}
-              textareaProps={{
-                placeholder: t(getTypeSafei18nKey(`tasks:${taskType.id}.response_placeholder`)),
-                isDisabled,
-                isReadOnly: !isEditable,
-              }}
-            />
+            <div hidden={!isEditable}>
+              <TrackedTextarea
+                text={inputText}
+                onTextChange={textChangeHandler}
+                thresholds={{ low: 20, medium: 40, goal: 50 }}
+                textareaProps={{
+                  placeholder: t(getTypeSafei18nKey(`tasks:${taskType.id}.response_placeholder`)),
+                  isDisabled,
+                  isReadOnly: !isEditable,
+                }}
+              />
+            </div>
+            {renderedMessage}
           </Stack>
         </>
       </TwoColumnsWithCards>

Line spacing is interestingly not a problem for this Review rendering. So maybe there is an issue with the message block styling.

mashdragon avatar Feb 13 '23 17:02 mashdragon

@mashdragon Thank you for the feedback, I will check it again tomorrow. About render mark markdown when editing, I plan to make it in another PR and add auto grow feature to the textarea too.

notmd avatar Feb 13 '23 17:02 notmd

One other place that needs rendering is in the modals of the ranking task. I did not remember that before.

mashdragon avatar Feb 13 '23 18:02 mashdragon

@mashdragon I just tweak style (heading space only) similar to boostrap which is the CSS framework Github use. Can you take a look at the style?

notmd avatar Feb 15 '23 13:02 notmd

I am not really sure what is the reason for the disabling css reset stuff / using chakra reset? but anyway looks good!

AbdBarho avatar Feb 15 '23 18:02 AbdBarho

I am not really sure what is the reason for the disabling css reset stuff / using chakra reset? but anyway looks good!

Tailwind also reset style ol tag . I just look overall the site when change CSS reset to Charka, it still look good.

notmd avatar Feb 15 '23 18:02 notmd