Skip to content

Commit

Permalink
🐛 Fix unwanted continuous numbering for some enumerated types (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch authored Jan 28, 2025
1 parent 9505e27 commit eacacd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-seals-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-transforms': patch
---

Fix unwanted continuous numbering for some enumerated types
22 changes: 18 additions & 4 deletions packages/myst-transforms/src/enumerate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('initializeTargetCounts', () => {
const previousCounts = {
heading: [5, 3, 1, 0, null, null],
figure: { main: 7, sub: 2 },
other: { main: 0, sub: 0 },
other: { main: 3, sub: 0 },
};
expect(
initializeTargetCounts(
Expand All @@ -172,15 +172,13 @@ describe('initializeTargetCounts', () => {
other: { continue: true, enabled: true },
},
previousCounts as any,
undefined,
),
).toEqual(previousCounts);
});
test('explicit numberings override previous', () => {
const previousCounts = {
heading: [5, 3, 1, 0, null, null],
figure: { main: 7, sub: 2 },
other: { main: 0, sub: 0 },
};
const numbering = {
heading_1: { enabled: true, start: 5, continue: true },
Expand All @@ -192,8 +190,24 @@ describe('initializeTargetCounts', () => {
expect(initializeTargetCounts(numbering, previousCounts as any)).toEqual({
heading: [4, null, 0, 0, 1, 0],
figure: { main: 4, sub: 0 },
other: { main: 0, sub: 0 },
code: { main: 7, sub: 0 },
});
});
test('unknown numberings reset from previousCounts', () => {
const previousCounts = {
heading: [5, 3, 1, 0, null, null],
figure: { main: 7, sub: 2 },
exercise: { main: 5, sub: 0 },
};
const numbering = {
heading_1: { enabled: true, start: 5, continue: true },
heading_2: { enabled: false, start: 2, continue: true },
heading_5: { enabled: true, start: 2, continue: true },
figure: { enabled: true, start: 5, continue: true },
};
expect(initializeTargetCounts(numbering, previousCounts as any)).toEqual({
heading: [4, null, 0, 0, 1, 0],
figure: { main: 4, sub: 0 },
});
});
});
2 changes: 1 addition & 1 deletion packages/myst-transforms/src/enumerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export function initializeTargetCounts(
// Update with other initial values
Object.entries(previousCounts ?? {})
.filter(([key]) => key !== 'heading')
.filter(([key]) => !numbering[key] || numbering[key]?.continue || numbering.all?.continue)
.filter(([key]) => numbering[key]?.continue || numbering.all?.continue)
.forEach(([key, val]) => {
targetCounts[key] = { ...(val as { main: number; sub: number }) };
});
Expand Down

0 comments on commit eacacd9

Please sign in to comment.