From 8f759d1c3e2ba616427faf46df323190c2799fdb Mon Sep 17 00:00:00 2001 From: lyf <1910527151@qq.com> Date: Fri, 9 Aug 2024 14:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/markdown.tsx | 60 ++++++++++++++++++++----------------- app/styles/globals.scss | 33 +++++++++++++------- 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 4b90bb705..e011bd5f5 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -127,44 +127,50 @@ export function PreCode(props: { children: any }) { useEffect(() => { if (ref.current) { - // 获取代码块的实际高度 - const screenHeight = window.innerHeight; const codeHeight = ref.current.scrollHeight; - setShowToggle(codeHeight > screenHeight * 0.3); + setShowToggle(codeHeight > 400); + ref.current.scrollTop = ref.current.scrollHeight; } }, [props.children]); const toggleCollapsed = () => { setCollapsed(!collapsed); }; - console.log(props.children); return ( <> -
- {
- if (ref.current) {
- const code = ref.current.innerText;
- copyToClipboard(code);
- }
+
+
- {props.children}
- {showToggle && collapsed && (
-
- 展开全部
-
- )}
-
+ >
+ {
+ if (ref.current) {
+ const code = ref.current.innerText;
+ copyToClipboard(code);
+ }
+ }}
+ >
+ {props.children}
+ {showToggle && collapsed && (
+
+
+
+ )}
+
+
{mermaidCode.length > 0 && (
)}
diff --git a/app/styles/globals.scss b/app/styles/globals.scss
index 679bac37a..14075a0a8 100644
--- a/app/styles/globals.scss
+++ b/app/styles/globals.scss
@@ -271,7 +271,7 @@ div.math {
}
pre {
- position: relative;
+ // position: relative;
&:hover .copy-code-button {
pointer-events: all;
transform: translateX(0px);
@@ -301,19 +301,32 @@ pre {
opacity: 1;
}
}
+
.show-hide-button {
- width: 100%;
- height: 20px;
- line-height: 20px;
- position: absolute;
- text-align: center;
- bottom: 0;
- cursor: pointer;
- color: white;
- background: linear-gradient(rgba(0,0,0,.3), #1a1b26);
+ position: absolute;
+ top: 0;
+ width: 100%;
+ margin: auto;
+ height: fit-content;
+ display: inline-flex;
+ justify-content: center;
+ button{
+ margin-top: 3em;
+ margin-bottom: 4em;
+ padding: 5px 16px;
+ border: 0;
+ cursor: pointer;
+ border-radius: 14px;
+ text-align: center;
+ color: white;
+ background: #464e4e;
+ }
}
+
}
+
+
.clickable {
cursor: pointer;