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 Program 1 vs Code 1 in typst #1599

Merged
merged 2 commits into from
Oct 22, 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/rude-deers-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-to-typst": patch
---

Typst program vs code.
9 changes: 8 additions & 1 deletion packages/myst-to-typst/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ function renderFigureChild(node: GenericNode, state: ITypstSerializer) {
if (useBrackets) state.write('\n]');
}

function getDefaultCaptionSupplement(kind: CaptionKind | string) {
if (kind === 'code') kind = 'program';
const domain = kind.includes(':') ? kind.split(':')[1] : kind;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Nice little extra improvement.

return `${domain.slice(0, 1).toUpperCase()}${domain.slice(1)}`;
}

export const containerHandler: Handler = (node, state) => {
if (state.data.isInTable) {
fileError(state.file, 'Unable to render typst figure inside table', {
Expand Down Expand Up @@ -117,8 +123,9 @@ export const containerHandler: Handler = (node, state) => {
state.write('\n],');
}
if (kind) {
const supplement = getDefaultCaptionSupplement(kind);
state.write(`\n kind: "${kind}",`);
state.write(`\n supplement: [${kind[0].toUpperCase() + kind.substring(1)}],`);
state.write(`\n supplement: [${supplement}],`);
}
state.write('\n)');
if (label) state.write(` <${label}>`);
Expand Down
4 changes: 2 additions & 2 deletions packages/mystmd/tests/notebook-fig-embed/outputs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"kind": "Notebook",
"slug": "interactive-notebooks",
"location": "/interactive-notebooks.ipynb",
"title": "Interactive Notebooks with MyST"
"title": "Generate and Display Rich Outputs"
}
},
{
Expand Down Expand Up @@ -273,7 +273,7 @@
"kind": "Notebook",
"slug": "interactive-notebooks",
"location": "/interactive-notebooks.ipynb",
"title": "Interactive Notebooks with MyST"
"title": "Generate and Display Rich Outputs"
},
"children": [
{
Expand Down
Loading