mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	Merge pull request #5136 from frostime/contrib-txtcode
✨ feat(markdown): 对纯文本的代码块内容进行折行处理
			
			
This commit is contained in:
		@@ -96,6 +96,32 @@ export function PreCode(props: { children: any }) {
 | 
			
		||||
    [plugins],
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  //Wrap the paragraph for plain-text
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (ref.current) {
 | 
			
		||||
      const codeElements = ref.current.querySelectorAll(
 | 
			
		||||
        "code",
 | 
			
		||||
      ) as NodeListOf<HTMLElement>;
 | 
			
		||||
      const wrapLanguages = [
 | 
			
		||||
        "",
 | 
			
		||||
        "md",
 | 
			
		||||
        "markdown",
 | 
			
		||||
        "text",
 | 
			
		||||
        "txt",
 | 
			
		||||
        "plaintext",
 | 
			
		||||
        "tex",
 | 
			
		||||
        "latex",
 | 
			
		||||
      ];
 | 
			
		||||
      codeElements.forEach((codeElement) => {
 | 
			
		||||
        let languageClass = codeElement.className.match(/language-(\w+)/);
 | 
			
		||||
        let name = languageClass ? languageClass[1] : "";
 | 
			
		||||
        if (wrapLanguages.includes(name)) {
 | 
			
		||||
          codeElement.style.whiteSpace = "pre-wrap";
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
      <pre ref={ref}>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user