Skip to content
Draft
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
8 changes: 8 additions & 0 deletions e2e-tests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ test("should switch language and show options for each", async ({ page }) => {
await expect(
page.getByRole("combobox", { exact: true, name: "Front Matter" }),
).toBeVisible();

// `Math` Switch
await expect(
page.getByRole("switch", {
exact: true,
name: "Math",
}),
).toBeVisible();
});

// CSS
Expand Down
14 changes: 13 additions & 1 deletion src/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const JSONPanel: FC = () => {
const MarkdownPanel: FC = () => {
const explorer = useExplorer();
const { markdownOptions, setMarkdownOptions } = explorer;
const { markdownMode, markdownFrontmatter } = markdownOptions;
const { markdownMode, markdownFrontmatter, markdownMath } = markdownOptions;
return (
<>
<LabeledSelect
Expand Down Expand Up @@ -96,6 +96,18 @@ const MarkdownPanel: FC = () => {
items={markdownFrontmatters}
placeholder="Front Matter"
/>

<LabeledSwitch
id="markdownMath"
label="Math"
checked={markdownMath}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

checked={markdownMath} assumes the value is always a boolean, but if a user has older persisted state (before markdownMath existed) it can be undefined and cause controlled/uncontrolled issues. Either ensure rehydration/migration fills markdownMath, or defensively coalesce here (e.g. default to false).

Suggested change
checked={markdownMath}
checked={markdownMath ?? false}

Copilot uses AI. Check for mistakes.
onCheckedChange={(value: boolean) => {
setMarkdownOptions({
...markdownOptions,
markdownMath: value,
});
}}
/>
</>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/use-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function useAST() {
}

case "markdown": {
const { markdownMode, markdownFrontmatter } = markdownOptions;
const { markdownMode, markdownFrontmatter, markdownMath } =
markdownOptions;
const language = markdown.languages[markdownMode];
astParseResult = language.parse(
{ body: code.markdown, path: "", physicalPath: "", bom: false },
Expand All @@ -76,6 +77,7 @@ export function useAST() {
markdownFrontmatter === "off"
? false
: markdownFrontmatter,
math: markdownMath,
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

If markdownMath is missing from rehydrated persisted state, math: markdownMath can be undefined. Consider defaulting this to false here (and/or adding a persist migration) so the parser option is always a boolean.

Suggested change
math: markdownMath,
math: markdownMath ?? false,

Copilot uses AI. Check for mistakes.
},
},
);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/use-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type JsonOptions = {
export type MarkdownOptions = {
markdownMode: MarkdownMode;
markdownFrontmatter: MarkdownFrontmatter;
markdownMath: boolean;
};

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Adding a new field to MarkdownOptions can break existing persisted state: zustand persist merges state shallowly, so older markdownOptions objects will overwrite defaultMarkdownOptions and may omit markdownMath, yielding undefined at runtime. Consider adding a persist version + migrate/custom merge, or patching rehydrated markdownOptions to include markdownMath: false when missing.

Suggested change
type PersistedMarkdownOptions = Omit<MarkdownOptions, "markdownMath"> & {
markdownMath?: boolean;
};
export const normalizeMarkdownOptions = (
markdownOptions?: PersistedMarkdownOptions,
): MarkdownOptions => ({
...defaultMarkdownOptions,
...markdownOptions,
markdownMath: markdownOptions?.markdownMath ?? false,
});

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, I'll dig into this problem a bit more in the near future.

export type CssOptions = {
Expand Down
1 change: 1 addition & 0 deletions src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ export const defaultJsonOptions: JsonOptions = {
export const defaultMarkdownOptions: MarkdownOptions = {
markdownMode: "commonmark",
markdownFrontmatter: "off",
markdownMath: false,
};

export const defaultCssOptions: CssOptions = {
Expand Down