I am using React ReactMarkdown to display a string which have numbered lists in it , the string is fetched using an api. But the it succesfully arranges the string line by line according to lists but it fails to display the numbers.
import React, { useEffect, useRef } from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
const Chat = ({ messages }) => {
const messageContainerRef = useRef(null);
useEffect(() => {
if (messageContainerRef.current) {
messageContainerRef.current.scrollTop =
messageContainerRef.current.scrollHeight;
}
}),
[messages];
return (
<div
className="w-full md:w-[50%] text-start overflow-y-scroll max-h-full"
ref={messageContainerRef}
>
<div className="flex flex-col gap-8 items-start">
{messages.length > 0 ? (
messages.map((message, index) => (
<div
className="text-white flex gap-3 items-start justify-center"
key={index}
>
{message.role == "user" ? (
<div className="w-7 h-7 rounded-2xl text-white text-center bg-[#3e3e54] border border-gray-50">
U
</div>
) : (
<img
src="/img/doge.webp"
alt=""
className="w-7 h-7 rounded-2xl"
/>
)}
<div>
<h1 className="font-bold ">
{message.role == "user" ? "You" : "VoiceGPT"}
</h1>
{message.role == "user" ? (
<p>{message.content}</p>
) : (
<ReactMarkdown remarkPlugins={[remarkGfm]}>
{message.content}
</ReactMarkdown>
)}
</div>
</div>
))
) : (
<>
<button></button>
</>
)}
</div>
</div>
);
};
export default Chat;
Result i got
Develop a plan
Make a list of tasks
Prioritize tasks
Start working on the first task
Complete the task
Evaluate progress
Adjust plan if necessary
Move on to the next task
Repeat steps 5-8 until all tasks are completed
Celebrate your accomplishments!
expected result
- Develop a plan
- Make a list of tasks
- Prioritize tasks
- Start working on the first task
- Complete the task
- Evaluate progress
- Adjust plan if necessary
- Move on to the next task
- Repeat steps 5-8 until all tasks are completed
- Celebrate your accomplishments!
I tried installing and using remarkGfm , but that doesnt seems to work.
please try this: you have to generate the numbers by yourself try this code :