Skip to content

Commit

Permalink
fix: respect enumerated
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Nov 20, 2024
1 parent e7d866a commit 8abd747
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/myst-ext-exercise/src/exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ export const exerciseDirective: DirectiveSpec = {
if (data.body) {
children.push(...(data.body as GenericNode[]));
}
const nonumber = (data.options?.nonumber as boolean) ?? false;

// Let `nonumber` take precedence over enumerated
let enumerated: boolean;
if (data.options?.nonumber !== undefined) {
enumerated = !data.options.nonumber as boolean;
} else {
enumerated = data.options?.enumerated as boolean;
}
const exercise: GenericNode = {
type: 'exercise',
hidden: data.options?.hidden as boolean,
enumerated: !nonumber,
enumerated,
children: children as any[],
};
addCommonDirectiveOptions(data, exercise);

// Numbered, unlabeled exercises still need a label
const backupLabel = nonumber ? undefined : `exercise-${createId()}`;
const backupLabel = enumerated ? `exercise-${createId()}` : undefined;
const rawLabel = (data.options?.label as string) || backupLabel;
const { label, identifier } = normalizeLabel(rawLabel) || {};
exercise.label = label;
Expand Down
11 changes: 9 additions & 2 deletions packages/myst-ext-proof/src/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ export const proofDirective: DirectiveSpec = {
if (data.body) {
children.push(...(data.body as GenericNode[]));
}
const nonumber = (data.options?.nonumber as boolean) ?? false;

// Let `nonumber` take precedence over enumerated
let enumerated: boolean;
if (data.options?.nonumber !== undefined) {
enumerated = !data.options.nonumber as boolean;
} else {
enumerated = data.options?.enumerated as boolean;
}
const proof = {
type: 'proof',
kind: data.name !== 'proof' ? data.name.replace('prf:', '') : undefined,
enumerated: !nonumber,
enumerated,
children: children as any[],
};
addCommonDirectiveOptions(data, proof);
Expand Down

0 comments on commit 8abd747

Please sign in to comment.