From d49ececcc58bf125bfad4deb4dbb161fd5f2339b Mon Sep 17 00:00:00 2001 From: frostime Date: Mon, 29 Jul 2024 19:10:00 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(markdown):=20wrap=20the=20plai?= =?UTF-8?q?n=20text=20code=20block?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/markdown.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index fc8df6fe33a..c12daed6468 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -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; + 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 ( <>