Skip to content

Commit

Permalink
🔧 Typst fixes for tables with divs and non-rgb cell colors (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch authored Jan 20, 2025
1 parent 415ed13 commit 74e96e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-meals-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-typst': patch
---

Support non-rgb colors in table cells
5 changes: 5 additions & 0 deletions .changeset/few-bulldogs-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-typst': patch
---

Fix containers with tables inside divs
3 changes: 2 additions & 1 deletion packages/myst-to-typst/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function determineCaptionKind(node: GenericNode): CaptionKind | null {
}

function renderFigureChild(node: GenericNode, state: ITypstSerializer) {
const useBrackets = node.type !== 'image' && node.type !== 'table';
const bracketNode = node.type === 'div' && node.children?.length === 1 ? node.children[0] : node;
const useBrackets = bracketNode.type !== 'image' && bracketNode.type !== 'table';
if (node.type === 'legend') {
state.useMacro('#let legendStyle = (fill: black.lighten(20%), size: 8pt, style: "italic")');
state.write('text(..legendStyle)');
Expand Down
4 changes: 3 additions & 1 deletion packages/myst-to-typst/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const tableCellHandler: Handler = (node, state) => {
state.write(`align: ${node.align}, `);
}
if (node.style?.backgroundColor) {
state.write(`fill: rgb("${node.style.backgroundColor}"), `);
const fill = node.style.backgroundColor as string;
const rgb = fill.startsWith('#');
state.write(`fill: ${rgb ? `rgb("${fill}")` : fill}, `);
}
state.write(')');
}
Expand Down

0 comments on commit 74e96e1

Please sign in to comment.