Skip to content

Commit c0ba332

Browse files
committed
1 parent b3211d1 commit c0ba332

File tree

3 files changed

+68
-54
lines changed

3 files changed

+68
-54
lines changed

src/svelteInMarkdown.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as v from "valibot"
22
import type { PreprocessorGroup } from "svelte/compiler"
33

4-
import { type ConfigInput, type ConfigOutput, ConfigSchema } from "./types.js"
4+
import { type ConfigInput, ConfigSchema } from "./types.js"
55
import { markupPreprocessor } from "./markupPreprocessor.js"
66

77
/**
@@ -36,8 +36,7 @@ import { markupPreprocessor } from "./markupPreprocessor.js"
3636
* ```
3737
*/
3838
export const svelteInMarkdown = (config?: ConfigInput) => {
39-
// TODO: [^1]
40-
const config_: ConfigOutput = v.parse(ConfigSchema, config)
39+
const config_ = v.parse(ConfigSchema, config)
4140

4241
return {
4342
name: "svelte-in-markdown",

src/transformers/unified/transformer.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
ConfigInput as SvelteInMarkdownConfigInput,
2828
ConfigOutput as SvelteInMarkdownConfigOutput,
2929
} from "../../types.js"
30-
import { ConfigSchema, type ConfigInput, type ConfigOutput } from "./types.js"
30+
import { ConfigSchema, type ConfigInput } from "./types.js"
3131
import { isHrefExternal } from "./isHrefExternal.js"
3232

3333
/**
@@ -38,8 +38,7 @@ export const transformer = (async (
3838
svelteInMarkdownConfig: SvelteInMarkdownConfigOutput,
3939
config?: ConfigInput
4040
) => {
41-
// TODO: [^1]
42-
const config_: ConfigOutput = v.parse(ConfigSchema, config)
41+
const config_ = v.parse(ConfigSchema, config)
4342

4443
const processor = unified()
4544

src/transformers/unified/types.ts

+64-48
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ const CustomPluginsSchema = v.optional(
2424
)
2525
)
2626

27+
// TODO: https://github.com/microsoft/TypeScript/issues/42873
28+
import * as _1 from "../../../node_modules/.pnpm/[email protected]/node_modules/yaml/dist/index.js"
29+
import * as _2 from "../../../node_modules/remark-gfm/lib/index.js"
30+
import * as _3 from "../../../node_modules/.pnpm/[email protected]/node_modules/mdast-util-toc/lib/index.js"
31+
import * as _4 from "../../../node_modules/rehype-slug/lib/index.js"
32+
import * as _5 from "../../../node_modules/rehype-autolink-headings/lib/index.js"
33+
import * as _6 from "../../../node_modules/rehype-external-links/lib/index.js"
34+
2735
export const ConfigSchema = v.optional(
2836
v.object(
2937
{
@@ -48,6 +56,12 @@ export const ConfigSchema = v.optional(
4856
"yaml"
4957
),
5058

59+
options: v.optional(
60+
v.special<RemarkFrontmatterCustomOptions>(
61+
() => true
62+
)
63+
),
64+
5165
/** Useful to add a plugin before or after this plugin. */
5266
plugins: CustomPluginsSchema,
5367
},
@@ -66,6 +80,12 @@ export const ConfigSchema = v.optional(
6680
/** @default true */
6781
enable: v.optional(v.boolean(), true),
6882

83+
options: v.optional(
84+
v.special<RemarkFrontmatterYamlOptions>(
85+
() => true
86+
)
87+
),
88+
6989
/** Useful to add a plugin before or after this plugin. */
7090
plugins: CustomPluginsSchema,
7191
},
@@ -81,6 +101,10 @@ export const ConfigSchema = v.optional(
81101
/** @default true */
82102
enable: v.optional(v.boolean(), true),
83103

104+
options: v.optional(
105+
v.special<RemarkGfmOptions>(() => true)
106+
),
107+
84108
/** Useful to add a plugin before or after this plugin. */
85109
plugins: CustomPluginsSchema,
86110
},
@@ -125,6 +149,10 @@ export const ConfigSchema = v.optional(
125149
/** @default true */
126150
enable: v.optional(v.boolean(), true),
127151

152+
options: v.optional(
153+
v.special<RemarkTocOptions>(() => true)
154+
),
155+
128156
/** Useful to add a plugin before or after this plugin. */
129157
plugins: CustomPluginsSchema,
130158
},
@@ -140,6 +168,12 @@ export const ConfigSchema = v.optional(
140168
remarkRehype: v.optional(
141169
v.object(
142170
{
171+
options: v.optional(
172+
v.special<OmittedRemarkRehypeOptions>(
173+
() => true
174+
)
175+
),
176+
143177
/** Useful to add a plugin before or after this plugin. */
144178
plugins: CustomPluginsSchema,
145179
},
@@ -167,6 +201,10 @@ export const ConfigSchema = v.optional(
167201
/** @default true */
168202
enable: v.optional(v.boolean(), true),
169203

204+
options: v.optional(
205+
v.special<RehypeSlugOptions>(() => true)
206+
),
207+
170208
/** Useful to add a plugin before or after this plugin. */
171209
plugins: CustomPluginsSchema,
172210
},
@@ -208,6 +246,12 @@ export const ConfigSchema = v.optional(
208246
/** @default false */
209247
enable: v.optional(v.boolean(), false),
210248

249+
options: v.optional(
250+
v.special<RehypeAutolinkHeadingsOptions>(
251+
() => true
252+
)
253+
),
254+
211255
/** Useful to add a plugin before or after this plugin. */
212256
plugins: CustomPluginsSchema,
213257
},
@@ -245,6 +289,12 @@ export const ConfigSchema = v.optional(
245289
/** @default true */
246290
enable: v.optional(v.boolean(), true),
247291

292+
options: v.optional(
293+
v.special<RehypeShikiOptions>(
294+
() => true
295+
)
296+
),
297+
248298
/** Useful to add a plugin before or after this plugin. */
249299
plugins: CustomPluginsSchema,
250300
},
@@ -297,6 +347,12 @@ export const ConfigSchema = v.optional(
297347
/** @default true */
298348
enable: v.optional(v.boolean(), true),
299349

350+
options: v.optional(
351+
v.special<RehypeExternalLinksOptions>(
352+
() => true
353+
)
354+
),
355+
300356
/** Useful to add a plugin before or after this plugin. */
301357
plugins: CustomPluginsSchema,
302358
},
@@ -312,6 +368,12 @@ export const ConfigSchema = v.optional(
312368
rehypeStringify: v.optional(
313369
v.object(
314370
{
371+
options: v.optional(
372+
v.special<OmittedRehypeStringifyOptions>(
373+
() => true
374+
)
375+
),
376+
315377
/** Useful to add a plugin before or after this plugin. */
316378
plugins: CustomPluginsSchema,
317379
},
@@ -367,51 +429,5 @@ type OmittedRehypeStringifyOptions = Omit<
367429
"allowDangerousCharacters" | "allowDangerousHtml"
368430
>
369431

370-
// TODO: [^1]
371-
type BuiltInPluginsOptions = {
372-
builtInPlugins: {
373-
remarkFrontmatter: {
374-
options?: RemarkFrontmatterCustomOptions
375-
}
376-
remarkFrontmatterYaml: {
377-
options?: RemarkFrontmatterYamlOptions
378-
}
379-
remarkGfm: {
380-
options?: RemarkGfmOptions
381-
}
382-
remarkToc: {
383-
options?: RemarkTocOptions
384-
}
385-
remarkRehype: {
386-
options?: OmittedRemarkRehypeOptions
387-
}
388-
rehypeSlug: {
389-
options?: RehypeSlugOptions
390-
}
391-
rehypeAutolinkHeadings: {
392-
options?: RehypeAutolinkHeadingsOptions
393-
}
394-
rehypeShiki: {
395-
options?: RehypeShikiOptions
396-
}
397-
rehypeExternalLinks: {
398-
options?: RehypeExternalLinksOptions
399-
}
400-
rehypeStringify: {
401-
options?: OmittedRehypeStringifyOptions
402-
}
403-
}
404-
}
405-
406-
// TODO: [^1]
407-
export type ConfigInput = v.Input<typeof ConfigSchema> &
408-
Partial<BuiltInPluginsOptions>
409-
410-
// TODO: [^1]
411-
export type ConfigOutput = v.Output<typeof ConfigSchema> & BuiltInPluginsOptions
412-
413-
/*
414-
[^1]: TypeScript types with Valibot
415-
- This is how to use TypeScript types with Valibot: https://github.com/fabian-hiller/valibot/discussions/477.
416-
- Whenever https://github.com/microsoft/TypeScript/issues/42873 fixes, move the extra types from `ConfigInput` and `ConfigOutput` to the schema itself.
417-
*/
432+
export type ConfigInput = v.Input<typeof ConfigSchema>
433+
export type ConfigOutput = v.Output<typeof ConfigSchema>

0 commit comments

Comments
 (0)