perf: md解析样式

This commit is contained in:
archer
2023-03-05 15:28:46 +08:00
parent c03a7db633
commit 45ad3ba22a
5 changed files with 23 additions and 10 deletions

View File

@@ -129,7 +129,8 @@
.markdown ul, .markdown ul,
.markdown ol, .markdown ol,
.markdown dl, .markdown dl,
.markdown table { .markdown table,
.markdown pre {
margin: 15px 0; margin: 15px 0;
} }
.markdown hr { .markdown hr {
@@ -242,7 +243,7 @@
border-top: 1px solid #cccccc; border-top: 1px solid #cccccc;
} }
.markdown table tr:nth-child(2n) { .markdown table tr:nth-child(2n) {
background-color: #f8f8f8; background-color: #f0f0f0;
} }
.markdown img { .markdown img {
max-width: 100%; max-width: 100%;
@@ -323,7 +324,8 @@
} }
.markdown code, .markdown code,
.markdown tt { .markdown tt {
background-color: #f8f8f8; background-color: #f0f0f0;
border: 1px solid #eaeaea;
border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px;
margin: 0 2px; margin: 0 2px;
padding: 0 5px; padding: 0 5px;
@@ -331,13 +333,16 @@
} }
.markdown pre > code { .markdown pre > code {
background: none repeat scroll 0 0 transparent; background: none repeat scroll 0 0 transparent;
border: medium none;
margin: 0; margin: 0;
padding: 0; padding: 0;
white-space: pre; white-space: pre;
} }
.markdown .highlight pre, .markdown .highlight pre,
.markdown pre { .markdown pre {
background-color: #f8f8f8; background-color: #f0f0f0;
border: 1px solid #cccccc;
border-radius: 3px 3px 3px 3px;
font-size: 13px; font-size: 13px;
line-height: 19px; line-height: 19px;
overflow: auto; overflow: auto;
@@ -353,11 +358,14 @@
line-height: 1.6; line-height: 1.6;
letter-spacing: 0.5px; letter-spacing: 0.5px;
text-align: justify; text-align: justify;
white-space: pre;
pre { pre {
display: block; display: block;
width: 100%; width: 100%;
padding: 15px; padding: 15px;
margin: 0;
border: none;
border-radius: 0;
background-color: #222 !important; background-color: #222 !important;
overflow-x: auto; overflow-x: auto;
} }

View File

@@ -11,15 +11,14 @@ import Icon from '@/components/Icon';
const Markdown = ({ source, isChatting }: { source: string; isChatting: boolean }) => { const Markdown = ({ source, isChatting }: { source: string; isChatting: boolean }) => {
// const formatSource = useMemo(() => source.replace(/\n/g, '\n'), [source]); // const formatSource = useMemo(() => source.replace(/\n/g, '\n'), [source]);
const { copyData } = useCopyData(); const { copyData } = useCopyData();
// console.log(source);
return ( return (
<ReactMarkdown <ReactMarkdown
className={`${styles.markdown} ${ className={`${styles.markdown} ${
isChatting ? (source === '' ? styles.waitingAnimation : styles.animation) : '' isChatting ? (source === '' ? styles.waitingAnimation : styles.animation) : ''
}`} }`}
rehypePlugins={[remarkGfm]} rehypePlugins={[remarkGfm]}
skipHtml={true}
components={{ components={{
p: 'div',
pre: 'div', pre: 'div',
code({ node, inline, className, children, ...props }) { code({ node, inline, className, children, ...props }) {
const match = /language-(\w+)/.exec(className || ''); const match = /language-(\w+)/.exec(className || '');

View File

@@ -6,8 +6,7 @@ export enum EmailTypeEnum {
export const introPage = ` export const introPage = `
## 欢迎使用 Doc GPT ## 欢迎使用 Doc GPT
时间比较赶,介绍没来得及完善,先直接上怎么使用 时间比较赶,介绍没来得及完善,先直接上怎么使用:
1. 使用邮箱注册账号。 1. 使用邮箱注册账号。
2. 进入账号页面,添加关联账号,目前只有 openai 的账号可以添加,直接去 openai 官网,把 API Key 粘贴过来。 2. 进入账号页面,添加关联账号,目前只有 openai 的账号可以添加,直接去 openai 官网,把 API Key 粘贴过来。
3. 进入模型页,创建一个模型,建议直接用 ChatGPT。 3. 进入模型页,创建一个模型,建议直接用 ChatGPT。

View File

@@ -50,6 +50,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
content: item.value content: item.value
}) })
); );
// 第一句话,强调代码类型
formatPrompts.unshift({
role: ChatCompletionRequestMessageRoleEnum.System,
content:
'If the content is code or code blocks, please label the code type as accurately as possible.'
});
// 获取 chatAPI // 获取 chatAPI
const chatAPI = getOpenAIApi(userApiKey); const chatAPI = getOpenAIApi(userApiKey);
const chatResponse = await chatAPI.createChatCompletion( const chatResponse = await chatAPI.createChatCompletion(

View File

@@ -306,7 +306,7 @@ const Chat = () => {
isChatting={isChatting && index === chatList.length - 1} isChatting={isChatting && index === chatList.length - 1}
/> />
) : ( ) : (
<Box whiteSpace={'pre'}>{item.value}</Box> <Box whiteSpace={'pre-wrap'}>{item.value}</Box>
)} )}
</Box> </Box>
</Flex> </Flex>