mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	[Feature] Better JSON Exporter #2692
[+] A view looks better [+] auto minify json when click a copy in markdown and download Co-Authored-By: wangwentong-lunaon <39506652+wangwentong-lunaon@users.noreply.github.com> Co-Authored-By: Yifei Zhang <yidadaa@qq.com> Co-Authored-By: B0zal <48602426+kfear1337@users.noreply.github.com>
This commit is contained in:
		@@ -565,21 +565,32 @@ export function MarkdownPreviewer(props: {
 | 
				
			|||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// modified by BackTrackZ now it's looks better
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function JsonPreviewer(props: {
 | 
					export function JsonPreviewer(props: {
 | 
				
			||||||
  messages: ChatMessage[];
 | 
					  messages: ChatMessage[];
 | 
				
			||||||
  topic: string;
 | 
					  topic: string;
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
  const msgs = props.messages.map((m) => ({
 | 
					  const msgs = {
 | 
				
			||||||
    role: m.role,
 | 
					    messages: [
 | 
				
			||||||
    content: m.content,
 | 
					      {
 | 
				
			||||||
  }));
 | 
					        role: "system",
 | 
				
			||||||
  const mdText = "\n" + JSON.stringify(msgs, null, 2) + "\n";
 | 
					        content: "You are an assistant that " + props.topic,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      ...props.messages.map((m) => ({
 | 
				
			||||||
 | 
					        role: m.role,
 | 
				
			||||||
 | 
					        content: m.content,
 | 
				
			||||||
 | 
					      })),
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  const mdText = "```json\n" + JSON.stringify(msgs, null, 2) + "\n```";
 | 
				
			||||||
 | 
					  const minifiedJson = JSON.stringify(msgs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const copy = () => {
 | 
					  const copy = () => {
 | 
				
			||||||
    copyToClipboard(JSON.stringify(msgs, null, 2));
 | 
					    copyToClipboard(minifiedJson);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  const download = () => {
 | 
					  const download = () => {
 | 
				
			||||||
    downloadAs(JSON.stringify(msgs, null, 2), `${props.topic}.json`);
 | 
					    downloadAs(JSON.stringify(msgs), `${props.topic}.json`);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
@@ -587,12 +598,12 @@ export function JsonPreviewer(props: {
 | 
				
			|||||||
      <PreviewActions
 | 
					      <PreviewActions
 | 
				
			||||||
        copy={copy}
 | 
					        copy={copy}
 | 
				
			||||||
        download={download}
 | 
					        download={download}
 | 
				
			||||||
        showCopy={true}
 | 
					        showCopy={false}
 | 
				
			||||||
        messages={props.messages}
 | 
					        messages={props.messages}
 | 
				
			||||||
      />
 | 
					      />
 | 
				
			||||||
      <div className="markdown-body">
 | 
					      <div className="markdown-body" onClick={copy}>
 | 
				
			||||||
        <pre className={styles["export-content"]}>{mdText}</pre>
 | 
					      <Markdown content={mdText} />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </>
 | 
					    </>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user