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

View File

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