Skip to content

Commit

Permalink
πŸ‘©β€πŸ’» Add Program 1 vs Code 1 in typst (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Oct 22, 2024
1 parent 5d828b8 commit 7547b1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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;
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

0 comments on commit 7547b1d

Please sign in to comment.