feat: md preview

This commit is contained in:
2025-06-03 23:09:33 +08:00
parent 63d21d6614
commit cfade95e97
8 changed files with 162 additions and 32 deletions

44
src/apps/preview/md.tsx Normal file
View File

@@ -0,0 +1,44 @@
import { ToastProvider } from '@/modules/toast/Provider';
import { query } from '@/modules/query';
import { useEffect, useState } from 'react';
import { MarkdownPreview } from '@/components/html/md/Preview';
export const App = () => {
return (
<ToastProvider>
<Main />
</ToastProvider>
);
};
const Main = () => {
const [mdUrl, setMdUrl] = useState<string>('');
const [markdown, setMarkdown] = useState<string>('');
useEffect(() => {
const url = new URL(window.location.href);
const md = url.searchParams.get('md');
if (md) {
setMdUrl(md);
}
}, []);
useEffect(() => {
if (!mdUrl) return;
getMdContent(mdUrl);
}, [mdUrl]);
const getMdContent = async (url: string) => {
console.log('url', url);
const res = await query.fetchText({
url: url,
});
if (res.code === 200) {
console.log('Markdown content fetched:', res.data);
setMarkdown(res.data);
}
};
return (
<div className='bg-white w-full h-full py-2 '>
<MarkdownPreview content={markdown} />
</div>
);
};