unifast-bindings-node 0.0.10

High-performance Markdown/MDX compiler
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
use napi_derive::napi;
use std::collections::HashMap;
use unifast_core::api::json_compat::*;
use unifast_core::api::options::CompileOptions;

#[napi(object)]
pub struct JsGfmOptions {
    pub tables: Option<bool>,
    pub task_list: Option<bool>,
    pub strikethrough: Option<bool>,
    pub footnotes: Option<bool>,
    pub autolink: Option<bool>,
}

#[napi(object)]
pub struct JsFrontmatterOptions {
    pub yaml: Option<bool>,
    pub toml: Option<bool>,
    pub json: Option<bool>,
}

#[napi(object)]
pub struct JsSanitizeSchemaOptions {
    pub allowed_tags: Option<Vec<String>>,
    pub allowed_attributes: Option<HashMap<String, Vec<String>>>,
    pub allowed_protocols: Option<HashMap<String, Vec<String>>>,
}

#[napi(object)]
pub struct JsSanitizeOptions {
    pub enabled: Option<bool>,
    pub schema: Option<JsSanitizeSchemaOptions>,
}

#[napi(object)]
pub struct JsHighlightOptions {
    pub enabled: Option<bool>,
    pub engine: Option<String>,
}

#[napi(object)]
pub struct JsSlugOptions {
    pub mode: Option<String>,
}

#[napi(object)]
pub struct JsLineNumberOptions {
    pub enabled: Option<bool>,
}

#[napi(object)]
pub struct JsTocOptions {
    pub enabled: Option<bool>,
    pub max_depth: Option<u32>,
}

#[napi(object)]
pub struct JsDiagnosticsOptions {
    pub format: Option<String>,
}

#[napi(object)]
pub struct JsExternalLinksOptions {
    pub enabled: Option<bool>,
    pub rel: Option<String>,
    pub target: Option<String>,
}

#[napi(object)]
pub struct JsAutolinkHeadingsOptions {
    pub enabled: Option<bool>,
    pub behavior: Option<String>,
}

#[napi(object)]
pub struct JsSmartypantsOptions {
    pub enabled: Option<bool>,
    pub quotes: Option<bool>,
    pub dashes: Option<bool>,
    pub ellipses: Option<bool>,
}

#[napi(object)]
pub struct JsWikiLinkOptions {
    pub enabled: Option<bool>,
    pub href_template: Option<String>,
}

#[napi(object)]
pub struct JsCodeImportOptions {
    pub enabled: Option<bool>,
    pub root_dir: Option<String>,
}

#[napi(object)]
pub struct JsFeatureToggle {
    pub enabled: Option<bool>,
}

#[napi(object)]
pub struct JsAlertIconDef {
    pub svg: Option<String>,
    pub import_source: Option<String>,
    pub import_name: Option<String>,
}

#[napi(object)]
pub struct JsGithubAlertOptions {
    pub enabled: Option<bool>,
    pub icons: Option<String>,
    pub custom_icons: Option<HashMap<String, JsAlertIconDef>>,
}

#[napi(object)]
pub struct JsReadingTimeOptions {
    pub enabled: Option<bool>,
    pub words_per_minute: Option<u32>,
    pub cjk_chars_per_minute: Option<u32>,
}

#[napi(object)]
pub struct JsExcerptOptions {
    pub enabled: Option<bool>,
    pub separator: Option<String>,
    pub fallback_paragraphs: Option<u32>,
    pub fallback_characters: Option<u32>,
}

#[napi(object)]
pub struct JsImgLazyLoadingOptions {
    pub enabled: Option<bool>,
    pub skip_first: Option<u32>,
}

#[napi(object)]
pub struct JsAddClassesRule {
    pub selector: String,
    pub classes: String,
}

#[napi(object)]
pub struct JsAddClassesOptions {
    pub enabled: Option<bool>,
    pub rules: Option<Vec<JsAddClassesRule>>,
}

#[napi(object)]
pub struct JsHtmlCleanupOptions {
    pub remove_empty_nodes: Option<bool>,
    pub minify_whitespace: Option<bool>,
}

#[napi(object)]
pub struct JsCompileOptions {
    pub input_kind: Option<String>,
    pub output_kind: Option<String>,
    pub gfm: Option<JsGfmOptions>,
    pub frontmatter: Option<JsFrontmatterOptions>,
    pub raw_html: Option<String>,
    pub sanitize: Option<JsSanitizeOptions>,
    pub highlight: Option<JsHighlightOptions>,
    pub line_numbers: Option<JsLineNumberOptions>,
    pub slug: Option<JsSlugOptions>,
    pub toc: Option<JsTocOptions>,
    pub diagnostics: Option<JsDiagnosticsOptions>,
    pub external_links: Option<JsExternalLinksOptions>,
    pub autolink_headings: Option<JsAutolinkHeadingsOptions>,
    pub sectionize: Option<JsFeatureToggle>,
    pub breaks: Option<JsFeatureToggle>,
    pub smartypants: Option<JsSmartypantsOptions>,
    pub emoji: Option<JsFeatureToggle>,
    pub github_alert: Option<JsGithubAlertOptions>,
    pub math: Option<JsFeatureToggle>,
    pub directive: Option<JsFeatureToggle>,
    pub wiki_link: Option<JsWikiLinkOptions>,
    pub definition_list: Option<JsFeatureToggle>,
    pub ruby_annotation: Option<JsFeatureToggle>,
    pub cjk: Option<JsFeatureToggle>,
    pub code_import: Option<JsCodeImportOptions>,
    pub code_meta: Option<JsFeatureToggle>,
    pub figure: Option<JsFeatureToggle>,
    pub custom_heading_id: Option<JsFeatureToggle>,
    pub reading_time: Option<JsReadingTimeOptions>,
    pub excerpt: Option<JsExcerptOptions>,
    pub abbr: Option<JsFeatureToggle>,
    pub comment_removal: Option<JsFeatureToggle>,
    pub img_lazy_loading: Option<JsImgLazyLoadingOptions>,
    pub accessible_emoji: Option<JsFeatureToggle>,
    pub add_classes: Option<JsAddClassesOptions>,
    pub html_cleanup: Option<JsHtmlCleanupOptions>,
    pub minify: Option<JsFeatureToggle>,
}

// ─── Js* → Json* conversions (field mapping only, no business logic) ──

impl From<JsFeatureToggle> for JsonToggle {
    fn from(js: JsFeatureToggle) -> Self {
        Self {
            enabled: js.enabled,
        }
    }
}

impl From<JsGfmOptions> for JsonGfmOptions {
    fn from(js: JsGfmOptions) -> Self {
        Self {
            tables: js.tables,
            task_list: js.task_list,
            strikethrough: js.strikethrough,
            footnotes: js.footnotes,
            autolink: js.autolink,
        }
    }
}

impl From<JsFrontmatterOptions> for JsonFrontmatterOptions {
    fn from(js: JsFrontmatterOptions) -> Self {
        Self {
            yaml: js.yaml,
            toml: js.toml,
            json: js.json,
        }
    }
}

impl From<JsSanitizeSchemaOptions> for JsonSanitizeSchema {
    fn from(js: JsSanitizeSchemaOptions) -> Self {
        Self {
            allowed_tags: js.allowed_tags,
            allowed_attributes: js.allowed_attributes,
            allowed_protocols: js.allowed_protocols,
        }
    }
}

impl From<JsSanitizeOptions> for JsonSanitizeOptions {
    fn from(js: JsSanitizeOptions) -> Self {
        Self {
            enabled: js.enabled,
            schema: js.schema.map(Into::into),
        }
    }
}

impl From<JsHighlightOptions> for JsonHighlightOptions {
    fn from(js: JsHighlightOptions) -> Self {
        Self {
            enabled: js.enabled,
            engine: js.engine,
        }
    }
}

impl From<JsSlugOptions> for JsonSlugOptions {
    fn from(js: JsSlugOptions) -> Self {
        Self { mode: js.mode }
    }
}

impl From<JsTocOptions> for JsonTocOptions {
    fn from(js: JsTocOptions) -> Self {
        Self {
            enabled: js.enabled,
            max_depth: js.max_depth,
        }
    }
}

impl From<JsDiagnosticsOptions> for JsonDiagnosticsOptions {
    fn from(js: JsDiagnosticsOptions) -> Self {
        Self { format: js.format }
    }
}

impl From<JsExternalLinksOptions> for JsonExternalLinksOptions {
    fn from(js: JsExternalLinksOptions) -> Self {
        Self {
            enabled: js.enabled,
            rel: js.rel,
            target: js.target,
        }
    }
}

impl From<JsAutolinkHeadingsOptions> for JsonAutolinkHeadingsOptions {
    fn from(js: JsAutolinkHeadingsOptions) -> Self {
        Self {
            enabled: js.enabled,
            behavior: js.behavior,
        }
    }
}

impl From<JsSmartypantsOptions> for JsonSmartypantsOptions {
    fn from(js: JsSmartypantsOptions) -> Self {
        Self {
            enabled: js.enabled,
            quotes: js.quotes,
            dashes: js.dashes,
            ellipses: js.ellipses,
        }
    }
}

impl From<JsAlertIconDef> for JsonAlertIconDef {
    fn from(js: JsAlertIconDef) -> Self {
        Self {
            svg: js.svg,
            import_source: js.import_source,
            import_name: js.import_name,
        }
    }
}

impl From<JsGithubAlertOptions> for JsonGithubAlertOptions {
    fn from(js: JsGithubAlertOptions) -> Self {
        Self {
            enabled: js.enabled,
            icons: js.icons,
            custom_icons: js
                .custom_icons
                .map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
        }
    }
}

impl From<JsWikiLinkOptions> for JsonWikiLinkOptions {
    fn from(js: JsWikiLinkOptions) -> Self {
        Self {
            enabled: js.enabled,
            href_template: js.href_template,
        }
    }
}

impl From<JsCodeImportOptions> for JsonCodeImportOptions {
    fn from(js: JsCodeImportOptions) -> Self {
        Self {
            enabled: js.enabled,
            root_dir: js.root_dir,
        }
    }
}

impl From<JsReadingTimeOptions> for JsonReadingTimeOptions {
    fn from(js: JsReadingTimeOptions) -> Self {
        Self {
            enabled: js.enabled,
            words_per_minute: js.words_per_minute,
            cjk_chars_per_minute: js.cjk_chars_per_minute,
        }
    }
}

impl From<JsExcerptOptions> for JsonExcerptOptions {
    fn from(js: JsExcerptOptions) -> Self {
        Self {
            enabled: js.enabled,
            separator: js.separator,
            fallback_paragraphs: js.fallback_paragraphs,
            fallback_characters: js.fallback_characters,
        }
    }
}

impl From<JsImgLazyLoadingOptions> for JsonImgLazyLoadingOptions {
    fn from(js: JsImgLazyLoadingOptions) -> Self {
        Self {
            enabled: js.enabled,
            skip_first: js.skip_first,
        }
    }
}

impl From<JsAddClassesRule> for JsonAddClassesRule {
    fn from(js: JsAddClassesRule) -> Self {
        Self {
            selector: js.selector,
            classes: js.classes,
        }
    }
}

impl From<JsAddClassesOptions> for JsonAddClassesOptions {
    fn from(js: JsAddClassesOptions) -> Self {
        Self {
            enabled: js.enabled,
            rules: js.rules.map(|r| r.into_iter().map(Into::into).collect()),
        }
    }
}

impl From<JsHtmlCleanupOptions> for JsonHtmlCleanupOptions {
    fn from(js: JsHtmlCleanupOptions) -> Self {
        Self {
            remove_empty_nodes: js.remove_empty_nodes,
            minify_whitespace: js.minify_whitespace,
        }
    }
}

impl From<JsCompileOptions> for JsonCompileOptions {
    fn from(js: JsCompileOptions) -> Self {
        Self {
            input_kind: js.input_kind,
            output_kind: js.output_kind,
            raw_html: js.raw_html,
            gfm: js.gfm.map(Into::into),
            frontmatter: js.frontmatter.map(Into::into),
            sanitize: js.sanitize.map(Into::into),
            highlight: js.highlight.map(Into::into),
            line_numbers: js.line_numbers.map(|l| JsonToggle { enabled: l.enabled }),
            slug: js.slug.map(Into::into),
            toc: js.toc.map(Into::into),
            external_links: js.external_links.map(Into::into),
            autolink_headings: js.autolink_headings.map(Into::into),
            sectionize: js.sectionize.map(Into::into),
            breaks: js.breaks.map(Into::into),
            smartypants: js.smartypants.map(Into::into),
            emoji: js.emoji.map(Into::into),
            github_alert: js.github_alert.map(Into::into),
            math: js.math.map(Into::into),
            directive: js.directive.map(Into::into),
            wiki_link: js.wiki_link.map(Into::into),
            definition_list: js.definition_list.map(Into::into),
            ruby_annotation: js.ruby_annotation.map(Into::into),
            cjk: js.cjk.map(Into::into),
            code_import: js.code_import.map(Into::into),
            code_meta: js.code_meta.map(Into::into),
            figure: js.figure.map(Into::into),
            custom_heading_id: js.custom_heading_id.map(Into::into),
            reading_time: js.reading_time.map(Into::into),
            excerpt: js.excerpt.map(Into::into),
            abbr: js.abbr.map(Into::into),
            comment_removal: js.comment_removal.map(Into::into),
            img_lazy_loading: js.img_lazy_loading.map(Into::into),
            accessible_emoji: js.accessible_emoji.map(Into::into),
            add_classes: js.add_classes.map(Into::into),
            html_cleanup: js.html_cleanup.map(Into::into),
            minify: js.minify.map(Into::into),
            diagnostics: js.diagnostics.map(Into::into),
        }
    }
}

pub fn convert_options(js_opts: Option<JsCompileOptions>) -> CompileOptions {
    match js_opts {
        Some(js) => {
            let json_opts: JsonCompileOptions = js.into();
            json_opts.into()
        }
        None => CompileOptions::default(),
    }
}