mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	@@ -156,6 +156,46 @@ export function PreCode(props: { children: any }) {
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function CustomCode(props: { children: any }) {
 | 
			
		||||
  const ref = useRef<HTMLPreElement>(null);
 | 
			
		||||
  const [collapsed, setCollapsed] = useState(true);
 | 
			
		||||
  const [showToggle, setShowToggle] = useState(false);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (ref.current) {
 | 
			
		||||
      const codeHeight = ref.current.scrollHeight;
 | 
			
		||||
      setShowToggle(codeHeight > 400);
 | 
			
		||||
      ref.current.scrollTop = ref.current.scrollHeight;
 | 
			
		||||
    }
 | 
			
		||||
  }, [props.children]);
 | 
			
		||||
 | 
			
		||||
  const toggleCollapsed = () => {
 | 
			
		||||
    setCollapsed((collapsed) => !collapsed);
 | 
			
		||||
  };
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
      <code
 | 
			
		||||
        ref={ref}
 | 
			
		||||
        style={{
 | 
			
		||||
          maxHeight: collapsed ? "400px" : "none",
 | 
			
		||||
          overflowY: "hidden",
 | 
			
		||||
        }}
 | 
			
		||||
      >
 | 
			
		||||
        {props.children}
 | 
			
		||||
        {showToggle && collapsed && (
 | 
			
		||||
          <div
 | 
			
		||||
            className={`show-hide-button ${
 | 
			
		||||
              collapsed ? "collapsed" : "expanded"
 | 
			
		||||
            }`}
 | 
			
		||||
          >
 | 
			
		||||
            <button onClick={toggleCollapsed}>查看全部</button>
 | 
			
		||||
          </div>
 | 
			
		||||
        )}
 | 
			
		||||
      </code>
 | 
			
		||||
    </>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function escapeDollarNumber(text: string) {
 | 
			
		||||
  let escapedText = "";
 | 
			
		||||
 | 
			
		||||
@@ -211,6 +251,7 @@ function _MarkDownContent(props: { content: string }) {
 | 
			
		||||
      ]}
 | 
			
		||||
      components={{
 | 
			
		||||
        pre: PreCode,
 | 
			
		||||
        code: CustomCode,
 | 
			
		||||
        p: (pProps) => <p {...pProps} dir="auto" />,
 | 
			
		||||
        a: (aProps) => {
 | 
			
		||||
          const href = aProps.href || "";
 | 
			
		||||
 
 | 
			
		||||
@@ -272,7 +272,7 @@ div.math {
 | 
			
		||||
 | 
			
		||||
pre {
 | 
			
		||||
  position: relative;
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  &:hover .copy-code-button {
 | 
			
		||||
    pointer-events: all;
 | 
			
		||||
    transform: translateX(0px);
 | 
			
		||||
@@ -304,6 +304,37 @@ pre {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
code{
 | 
			
		||||
  .show-hide-button {
 | 
			
		||||
    border-radius: 10px;
 | 
			
		||||
    position: absolute;
 | 
			
		||||
    inset: 0 0 auto 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;
 | 
			
		||||
    } 
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  .expanded {
 | 
			
		||||
    background-image: none;
 | 
			
		||||
  }
 | 
			
		||||
  .collapsed {
 | 
			
		||||
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.06));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.clickable {
 | 
			
		||||
  cursor: pointer;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user