Closed champon1020 closed 3 years ago
const renderers = {
inlineCode: ({ children }) => {
if (/^\$\$(.*)\$\$/.test(children)) {
const html = katex.renderToString(children.replace(/^\$\$(.*)\$\$/, '$1'), {
throwOnError: false,
});
return <code dangerouslySetInnerHTML={{ __html: html }} />
}
- if (children == null) {
- return <code />;
- }
return children;
},
code: ({ children, language, value }) => {
if (language.toLocaleLowerCase() === 'katex') {
const html = katex.renderToString(value, {
throwOnError: false
});
return (
<pre>
<code dangerouslySetInnerHTML={{ __html: html }} />
</pre>
);
}
- if (children == null) {
- return <code />;
- }
return children;
}
}
@champon1020 The code is redundant.
<MDEditor
- value={mdKaTeX}
+ value={mdKaTeX === null ? '' : mdKaTeX}
/>
or
<MDEditor
- value={mdKaTeX}
+ value={mdKaTeX || ''}
/>
thx!
Thanks for your reply! I think this issue was solved so I'll close.
What
I ran the script for KaTeX preview written in README and got inlineCode error when I inserted two back quotes into editor.
code (written in README): https://codesandbox.io/s/markdown-editor-katex-for-react-7v3vl
Inserted two back quotes like this:
Found two errors:
Solution
I inserted the null check statement for children and got no errors.
I think it needs to update README and I wanna other solutions if you have. Thanks:)