Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#5136 from frostime/contrib-txtcode
Browse files Browse the repository at this point in the history
✨ feat(markdown): 对纯文本的代码块内容进行折行处理
  • Loading branch information
lloydzhou authored Aug 2, 2024
2 parents 9193a9a + d49ecec commit 324d30b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down

0 comments on commit 324d30b

Please sign in to comment.