Skip to content

Commit 324d30b

Browse files
authored
Merge pull request ChatGPTNextWeb#5136 from frostime/contrib-txtcode
✨ feat(markdown): 对纯文本的代码块内容进行折行处理
2 parents 9193a9a + d49ecec commit 324d30b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

app/components/markdown.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@ export function PreCode(props: { children: any }) {
9696
[plugins],
9797
);
9898

99+
//Wrap the paragraph for plain-text
100+
useEffect(() => {
101+
if (ref.current) {
102+
const codeElements = ref.current.querySelectorAll(
103+
"code",
104+
) as NodeListOf<HTMLElement>;
105+
const wrapLanguages = [
106+
"",
107+
"md",
108+
"markdown",
109+
"text",
110+
"txt",
111+
"plaintext",
112+
"tex",
113+
"latex",
114+
];
115+
codeElements.forEach((codeElement) => {
116+
let languageClass = codeElement.className.match(/language-(\w+)/);
117+
let name = languageClass ? languageClass[1] : "";
118+
if (wrapLanguages.includes(name)) {
119+
codeElement.style.whiteSpace = "pre-wrap";
120+
}
121+
});
122+
}
123+
}, []);
124+
99125
return (
100126
<>
101127
<pre ref={ref}>

0 commit comments

Comments
 (0)