Skip to content

Commit

Permalink
doc: Update README.md #105
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 2, 2021
1 parent 573eed6 commit 64e3c84
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ import MDEditor from '@uiw/react-md-editor';
import katex from 'katex';
import 'katex/dist/katex.css';


const mdKaTeX = `This is to display the
\`\$\$\c = \\pm\\sqrt{a^2 + b^2}\$\$\`
in one line
Expand All @@ -196,30 +195,37 @@ const renderers = {
const html = katex.renderToString(children.replace(/^\$\$(.*)\$\$/, '$1'), {
throwOnError: false,
});
return <code dangerouslySetInnerHTML={{ __html: html }} />
return <code dangerouslySetInnerHTML={{ __html: html }} />;
}
return children;
},
code: ({ children, language, value }) => {
if (language.toLocaleLowerCase() === 'katex') {
code: ({ language, value, children }) => {
if (language && language.toLocaleLowerCase() === 'katex') {
const html = katex.renderToString(value, {
throwOnError: false
throwOnError: false,
});
return (
<pre>
<code dangerouslySetInnerHTML={{ __html: html }} />
</pre>
);
}
return children;
}
const props = {
className: language ? `language-${language}` : '',
};
return (
<pre {...props}>
<code {...props}>{value}</code>
</pre>
);
},
}

export default function App() {
return (
<MDEditor
value={mdKaTeX || ''}
previewOptions={{ renderers: renderers }}
value={mdKaTeX}
previewOptions={{ renderers }}
/>
);
}
Expand Down

1 comment on commit 64e3c84

@vercel
Copy link

@vercel vercel bot commented on 64e3c84 Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.