Skip to content

Commit 7488f15

Browse files
committed
2 parents 0b0a24d + 77fda42 commit 7488f15

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

src/components/common/MarkdownRender.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,23 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
154154
onConvertFinish,
155155
editing,
156156
}) => {
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+
: '',
172170
);
173171

172+
const [element, setElement] = useState<RenderedElement>(null);
173+
174174
const applyElement = React.useMemo(() => {
175175
return throttle(250, (el: any) => {
176176
setElement(el);
@@ -195,6 +195,12 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
195195
// if (window && (window as any).twttr) return;
196196
loadScript('https://platform.twitter.com/widgets.js');
197197
}
198+
199+
if (!editing) {
200+
setHtml(html);
201+
return;
202+
}
203+
198204
const el = parse(editing ? html : filter(html));
199205

200206
applyElement(el);
@@ -203,7 +209,13 @@ const MarkdownRender: React.FC<MarkdownRenderProps> = ({
203209

204210
return (
205211
<Typography>
206-
<MarkdownRenderBlock className={codeTheme}>{element}</MarkdownRenderBlock>
212+
{editing ? (
213+
<MarkdownRenderBlock className={codeTheme}>
214+
{element}
215+
</MarkdownRenderBlock>
216+
) : (
217+
<MarkdownRenderBlock dangerouslySetInnerHTML={{ __html: html }} />
218+
)}
207219
</Typography>
208220
);
209221
};

0 commit comments

Comments
 (0)