Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧮 Inline user_expressions #58

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-birds-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Add inline expressions
2 changes: 2 additions & 0 deletions packages/myst-to-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import HEADING_RENDERERS from './heading';
import CROSS_REFERENCE_RENDERERS from './crossReference';
import TAB_RENDERERS from './tabs';
import EXT_RENDERERS from './extensions';
import INLINE_EXPRESSION_RENDERERS from './inlineExpression';

export { CopyIcon } from './components/CopyIcon';
export { CodeBlock } from './code';
Expand All @@ -42,6 +43,7 @@ export const DEFAULT_RENDERERS: Record<string, NodeRenderer> = {
...DROPDOWN_RENDERERS,
...CARD_RENDERERS,
...GRID_RENDERERS,
...INLINE_EXPRESSION_RENDERERS,
...EXT_RENDERERS,
};

Expand Down
23 changes: 23 additions & 0 deletions packages/myst-to-react/src/inlineExpression.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { NodeRenderer } from '@myst-theme/providers';
import { InlineError } from './inlineError';

export const InlineExpression: NodeRenderer = (node, children) => {
if (!node.result) {
return <InlineError value={`Unexecuted inline expression for: ${node.value}`} />;
}
if (node.result?.status !== 'ok') {
return <InlineError value={`${node.result?.ename}: ${node.result?.evalue}`} />;
}
// TODO: something with Thebe in the future!
return (
<span key={node.key} title={`Evaluated from: "${node.value}"`}>
{children}
</span>
);
};

const INLINE_EXPRESSION_RENDERERS = {
inlineExpression: InlineExpression,
};

export default INLINE_EXPRESSION_RENDERERS;