Skip to content

Commit f0651bf

Browse files
committed
tiny feature: export type of rehype-katex paramters
1 parent 715305d commit f0651bf

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"name": "@luma-dev/my-unified",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"description": "",
66
"files": [
77
"dist"

src/rehype-katex.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface MathTransform {
3737
}
3838

3939
const expressionOfMdxJsxExpressionAttribute = (
40-
attr: MdxJsxAttributeValueExpression,
40+
attr: MdxJsxAttributeValueExpression
4141
): Expression | null => {
4242
if (attr.data == null) return null;
4343
if (attr.data.estree == null) return null;
@@ -46,15 +46,15 @@ const expressionOfMdxJsxExpressionAttribute = (
4646
return attr.data.estree.body[0].expression;
4747
};
4848

49+
export type RehypeKatexPluginParameters =
50+
| Readonly<{
51+
languageDetection?: string;
52+
dynamicSuffix?: () => string;
53+
context?: string;
54+
}>
55+
| undefined;
4956
export type RehypeKatexPlugin = import("unified").Plugin<
50-
[
51-
| Readonly<{
52-
languageDetection?: string;
53-
dynamicSuffix?: () => string;
54-
context?: string;
55-
}>
56-
| undefined,
57-
],
57+
[RehypeKatexPluginParameters],
5858
Root
5959
>;
6060
const rehypeKatex: RehypeKatexPlugin = ({
@@ -85,11 +85,11 @@ const rehypeKatex: RehypeKatexPlugin = ({
8585
data: {
8686
estree: estreeDeleteCtx(dynamicKeyName),
8787
},
88-
},
88+
}
8989
);
9090
visit(tree, (node) => {
9191
const expressionOfMdxJsxExpressionAttributeOrReport = (
92-
attr: string | MdxJsxAttributeValueExpression | undefined | null,
92+
attr: string | MdxJsxAttributeValueExpression | undefined | null
9393
) => {
9494
if (typeof attr === "string" || attr == null) {
9595
return { ok: true as const, content: attr };
@@ -98,7 +98,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
9898
if (expression == null) {
9999
file.message(
100100
`Unreachable? Structure of MdxJsxExpressionAttribute is not expected`,
101-
node,
101+
node
102102
);
103103
return { ok: false };
104104
}
@@ -155,7 +155,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
155155
],
156156
children: [],
157157
} satisfies MdxJsxFlowElement,
158-
STEP_OVER,
158+
STEP_OVER
159159
);
160160
};
161161
const save = (content: MdxAttrValue, options: MdxAttrValue) => {
@@ -220,7 +220,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
220220
},
221221
],
222222
} satisfies MdxJsxFlowElement,
223-
STEP_OVER,
223+
STEP_OVER
224224
);
225225
};
226226
const def = (expressionLike: string | null | Expression) => {
@@ -241,7 +241,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
241241
estree: estreePushCtx(dynamicKeyName, expression),
242242
},
243243
} satisfies MdxFlowExpressionHast,
244-
STEP_OVER,
244+
STEP_OVER
245245
);
246246
};
247247
const reset = () => {
@@ -253,7 +253,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
253253
estree: estreeResetCtx(dynamicKeyName),
254254
},
255255
} satisfies MdxFlowExpressionHast,
256-
STEP_OVER,
256+
STEP_OVER
257257
);
258258
};
259259

@@ -269,7 +269,7 @@ const rehypeKatex: RehypeKatexPlugin = ({
269269
const classes = getClasses(codeEl);
270270
const languageClassPrefix = `language-${languageDetection}`;
271271
const langKind = Option.fromNullish(
272-
classes.find((e) => e.startsWith(languageClassPrefix)),
272+
classes.find((e) => e.startsWith(languageClassPrefix))
273273
)
274274
.map((e) => e.slice(languageClassPrefix.length))
275275
.unwrapOr(null);
@@ -306,12 +306,12 @@ const rehypeKatex: RehypeKatexPlugin = ({
306306
if (attr.type !== "mdxJsxAttribute") {
307307
file.message(
308308
`Unreachable? KatexDef attribute _ is not mdxJsxAttribute`,
309-
node,
309+
node
310310
);
311311
return STEP_OVER;
312312
}
313313
const maybe = expressionOfMdxJsxExpressionAttributeOrReport(
314-
attr.value,
314+
attr.value
315315
);
316316
if (!maybe.ok) {
317317
return DELETE;

0 commit comments

Comments
 (0)