Skip to content

Commit

Permalink
MathJax typeset redered md
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Jan 31, 2024
1 parent 08a184f commit 9eca8fe
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/jupyter-ai/src/components/rendermime-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CopyButton } from './copy-button';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { MathJaxTypesetter } from '@jupyterlab/mathjax-extension';

const MD_MIME_TYPE = 'text/markdown';
const RENDERMIME_MD_CLASS = 'jp-ai-rendermime-markdown';

type RendermimeMarkdownProps = {
Expand All @@ -20,17 +21,13 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {

useEffect(() => {
const renderContent = async () => {
const rmRegistry = props.rmRegistry.clone({
latexTypesetter: new MathJaxTypesetter()
const model = props.rmRegistry.createModel({
data: { [MD_MIME_TYPE]: props.markdownStr }
});

const mimeType = 'text/markdown';

const model = rmRegistry.createModel({
data: { [mimeType]: props.markdownStr }
});
const renderer = rmRegistry.createRenderer(mimeType);
const renderer = props.rmRegistry.createRenderer(MD_MIME_TYPE);
await renderer.renderModel(model);
const typesetter = new MathJaxTypesetter();
typesetter.typeset(renderer.node);
setRenderedContent(renderer.node);

// Attach CopyButton to each <pre> block
Expand Down

0 comments on commit 9eca8fe

Please sign in to comment.