moved markdown converter to the mardown component

This commit is contained in:
Chirag Bhalotia 2023-06-24 14:02:24 +05:30
parent 4567df6fdb
commit 16c648bddd
No known key found for this signature in database
GPG Key ID: F7F1F1FBFFD40427
2 changed files with 5 additions and 5 deletions

View File

@ -1,8 +1,6 @@
import Markdown from '@/components/Markdown';
import axios from 'axios';
import React from 'react';
import showdown from 'showdown';
const converter = new showdown.Converter();
const Dashboard = async () => {
const { data } = await axios.get(
@ -10,7 +8,7 @@ const Dashboard = async () => {
);
return (
<>
<Markdown markdown={converter.makeHtml(data)} />
<Markdown markdown={data} />
</>
);
};

View File

@ -1,8 +1,10 @@
'use client';
import React, { useEffect, useRef } from 'react';
import "github-markdown-css"
import showdown from 'showdown';
import 'github-markdown-css';
const converter = new showdown.Converter();
interface MarkdownProps {
markdown: string;
@ -11,7 +13,7 @@ interface MarkdownProps {
function Markdown({ markdown }: MarkdownProps) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (ref.current?.innerHTML) ref.current.innerHTML = markdown;
if (ref.current?.innerHTML) ref.current.innerHTML = converter.makeHtml(markdown);
}, [markdown]);
return (
<div className="markdown-body w-full p-10" ref={ref}>