File tree Expand file tree Collapse file tree 1 file changed +28
-16
lines changed Expand file tree Collapse file tree 1 file changed +28
-16
lines changed Original file line number Diff line number Diff line change @@ -154,23 +154,23 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
154
154
onConvertFinish,
155
155
editing,
156
156
} ) => {
157
- const initialHtml = ssrEnabled
158
- ? remark ( )
159
- . use ( breaks )
160
- . use ( prismPlugin )
161
- . use ( htmlPlugin , {
162
- sanitize : true ,
163
- } )
164
- . use ( embedPlugin )
165
- . use ( slug )
166
- . processSync ( markdown )
167
- . toString ( )
168
- : '' ;
169
-
170
- const [ element , setElement ] = useState < RenderedElement > (
171
- ssrEnabled ? parse ( filter ( initialHtml ) ) : null ,
157
+ const [ html , setHtml ] = useState (
158
+ ssrEnabled
159
+ ? remark ( )
160
+ . use ( breaks )
161
+ . use ( prismPlugin )
162
+ . use ( htmlPlugin , {
163
+ sanitize : true ,
164
+ } )
165
+ . use ( embedPlugin )
166
+ . use ( slug )
167
+ . processSync ( markdown )
168
+ . toString ( )
169
+ : '' ,
172
170
) ;
173
171
172
+ const [ element , setElement ] = useState < RenderedElement > ( null ) ;
173
+
174
174
const applyElement = React . useMemo ( ( ) => {
175
175
return throttle ( 250 , ( el : any ) => {
176
176
setElement ( el ) ;
@@ -195,6 +195,12 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
195
195
// if (window && (window as any).twttr) return;
196
196
loadScript ( 'https://platform.twitter.com/widgets.js' ) ;
197
197
}
198
+
199
+ if ( ! editing ) {
200
+ setHtml ( html ) ;
201
+ return ;
202
+ }
203
+
198
204
const el = parse ( editing ? html : filter ( html ) ) ;
199
205
200
206
applyElement ( el ) ;
@@ -203,7 +209,13 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
203
209
204
210
return (
205
211
< Typography >
206
- < MarkdownRenderBlock className = { codeTheme } > { element } </ MarkdownRenderBlock >
212
+ { editing ? (
213
+ < MarkdownRenderBlock className = { codeTheme } >
214
+ { element }
215
+ </ MarkdownRenderBlock >
216
+ ) : (
217
+ < MarkdownRenderBlock dangerouslySetInnerHTML = { { __html : html } } />
218
+ ) }
207
219
</ Typography >
208
220
) ;
209
221
} ;
You can’t perform that action at this time.
0 commit comments