File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff 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 ( / l a n g u a g e - ( \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 } >
You can’t perform that action at this time.
0 commit comments