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

💅 🖼️ Add topic directive #365

Merged
merged 1 commit into from
Apr 19, 2024
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/seven-hornets-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Support various types of margin content
55 changes: 55 additions & 0 deletions packages/myst-to-react/src/aside.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { NodeRenderer } from '@myst-theme/providers';
import { MyST } from './MyST.js';
import type { GenericNode } from 'myst-common';

type Aside = {
type: 'aside';
};

function getAsideClass(kind?: string) {
switch (kind) {
case 'topic':
return {
container: 'my-5 shadow dark:bg-stone-800 overflow-hidden dark:border-l-4 border-slate-400',
title:
'm-0 font-medium py-2 px-4 flex min-w-0 text-md border-y dark:border-y-0 bg-gray-50/80 dark:bg-slate-900',
body: 'px-4',
};
case 'margin':
case 'sidebar':
default:
return {
container: 'text-sm lg:h-0 col-margin-right',
title: 'text-base font-semibold',
body: '',
};
}
}

export const AsideRenderer: NodeRenderer<Aside> = ({ node }) => {
const [title, ...rest] = node.children as GenericNode[];
const className = getAsideClass(node.kind);
if (title.type !== 'admonitionTitle') {
return (
<aside className={className.container}>
<MyST ast={node.children} />
</aside>
);
}
return (
<aside className={className.container}>
<div className={className.title}>
<MyST ast={title} />
</div>
<div className={className.body}>
<MyST ast={rest} />
</div>
</aside>
);
};

const ASIDE_RENDERERS = {
aside: AsideRenderer,
};

export default ASIDE_RENDERERS;
12 changes: 0 additions & 12 deletions packages/myst-to-react/src/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ type CaptionNumber = {
identifier: string;
};

type Aside = {
type: 'aside';
};

type Keyboard = {
type: 'keyboard';
};
Expand Down Expand Up @@ -93,7 +89,6 @@ type BasicNodeRenderers = {
definitionList: NodeRenderer<DefinitionList>;
definitionTerm: NodeRenderer<DefinitionTerm>;
definitionDescription: NodeRenderer<DefinitionDescription>;
aside: NodeRenderer<Aside>;
include: NodeRenderer<Include>;
};

Expand Down Expand Up @@ -378,13 +373,6 @@ const BASIC_RENDERERS: BasicNodeRenderers = {
</dd>
);
},
aside({ node }) {
return (
<aside className="text-sm lg:h-0 col-margin-right">
<MyST ast={node.children} />
</aside>
);
},
keyboard({ node }) {
return (
<kbd>
Expand Down
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 @@ -19,6 +19,7 @@ import EXT_RENDERERS from './extensions/index.js';
import INLINE_EXPRESSION_RENDERERS from './inlineExpression.js';
import PROOF_RENDERERS from './proof.js';
import EXERCISE_RENDERERS from './exercise.js';
import ASIDE_RENDERERS from './aside.js';
import UNKNOWN_MYST_RENDERERS from './unknown.js';

export { CopyIcon, HoverPopover, Tooltip, LinkCard } from './components/index.js';
Expand Down Expand Up @@ -51,6 +52,7 @@ export const DEFAULT_RENDERERS: Record<string, NodeRenderer> = {
...EXT_RENDERERS,
...PROOF_RENDERERS,
...EXERCISE_RENDERERS,
...ASIDE_RENDERERS,
};

export { MyST } from './MyST.js';
Loading