@nuxtjs/mdc 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +3 -3
  2. package/dist/config.d.mts +6 -5
  3. package/dist/config.d.ts +6 -5
  4. package/dist/config.mjs +7 -5
  5. package/dist/module.d.mts +502 -3
  6. package/dist/module.d.ts +502 -3
  7. package/dist/module.json +2 -2
  8. package/dist/module.mjs +5 -2
  9. package/dist/runtime/components/MDC.vue +1 -1
  10. package/dist/runtime/components/MDCRenderer.vue.d.ts +0 -1
  11. package/dist/runtime/components/prose/ProseH1.vue +1 -1
  12. package/dist/runtime/components/prose/ProseH2.vue +1 -1
  13. package/dist/runtime/components/prose/ProseH3.vue +1 -1
  14. package/dist/runtime/components/prose/ProseH4.vue +1 -1
  15. package/dist/runtime/components/prose/ProseH5.vue +1 -1
  16. package/dist/runtime/components/prose/ProseH6.vue +1 -1
  17. package/dist/runtime/highlighter/rehype-nuxt.d.ts +1 -1
  18. package/dist/runtime/highlighter/rehype.d.ts +1 -5
  19. package/dist/runtime/highlighter/shiki.d.ts +1 -2
  20. package/dist/runtime/parser/compiler.d.ts +1 -1
  21. package/dist/runtime/parser/index.d.ts +1 -1
  22. package/dist/runtime/parser/options.d.ts +1 -1
  23. package/dist/runtime/parser/toc.d.ts +1 -1
  24. package/dist/runtime/parser/utils/plugins.d.ts +1 -1
  25. package/dist/runtime/utils/ast.d.ts +1 -1
  26. package/dist/runtime/utils/node.d.ts +1 -1
  27. package/dist/types.d.mts +7 -82
  28. package/dist/types.d.ts +7 -82
  29. package/package.json +15 -13
  30. package/dist/runtime/highlighter/types.d.ts +0 -14
  31. package/dist/runtime/highlighter/types.js +0 -0
  32. package/dist/runtime/types/config.d.ts +0 -44
  33. package/dist/runtime/types/config.js +0 -0
  34. package/dist/runtime/types/hast.d.ts +0 -255
  35. package/dist/runtime/types/hast.js +0 -0
  36. package/dist/runtime/types/index.d.ts +0 -3
  37. package/dist/runtime/types/index.js +0 -3
  38. package/dist/runtime/types/parser.d.ts +0 -41
  39. package/dist/runtime/types/parser.js +0 -0
  40. package/dist/runtime/types/toc.d.ts +0 -12
  41. package/dist/runtime/types/toc.js +0 -0
  42. package/dist/runtime/types/tree.d.ts +0 -23
  43. package/dist/runtime/types/tree.js +0 -0
  44. package/dist/runtime/types/unist.d.ts +0 -107
  45. package/dist/runtime/types/unist.js +0 -0
package/README.md CHANGED
@@ -76,7 +76,7 @@ This component will take the result of [`parseMarkdown`](#parsing-markdown) func
76
76
  <script setup lang="ts">
77
77
  import { parseMarkdown } from '@nuxtjs/mdc/runtime'
78
78
 
79
- const ast = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
79
+ const { data: ast } = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
80
80
  </script>
81
81
 
82
82
  <template>
@@ -196,7 +196,7 @@ The `parseMarkdown` function is a universal helper, and you can also use it in t
196
196
  <script setup lang="ts">
197
197
  import { parseMarkdown } from '@nuxtjs/mdc/runtime'
198
198
 
199
- const ast = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
199
+ const { data: ast } = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
200
200
  </script>
201
201
 
202
202
  <template>
@@ -367,7 +367,7 @@ Now import the `useMarkdownParser` composable we just created along with an expo
367
367
  import { onBeforeMount, ref, watch } from 'vue'
368
368
  // Import package exports
369
369
  import MDCRenderer from '@nuxtjs/mdc/runtime/components/MDCRenderer.vue'
370
- import type { MDCParserResult } from '@nuxtjs/mdc/runtime/types/index'
370
+ import type { MDCParserResult } from '@nuxtjs/mdc'
371
371
  import useMarkdownParser from './composables/useMarkdownParser';
372
372
 
373
373
  const md = ref(`
package/dist/config.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { MdcConfig } from '../dist/runtime/types/config.js';
2
-
3
- declare function defineConfig(config: MdcConfig): MdcConfig;
4
-
5
- export { defineConfig };
1
+ export { defineConfig } from './module.mjs';
2
+ import '@nuxt/schema';
3
+ import 'shiki';
4
+ import 'remark-rehype';
5
+ import 'unified';
6
+ import 'hast';
package/dist/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { MdcConfig } from '../dist/runtime/types/config.js';
2
-
3
- declare function defineConfig(config: MdcConfig): MdcConfig;
4
-
5
- export { defineConfig };
1
+ export { defineConfig } from './module.js';
2
+ import '@nuxt/schema';
3
+ import 'shiki';
4
+ import 'remark-rehype';
5
+ import 'unified';
6
+ import 'hast';
package/dist/config.mjs CHANGED
@@ -1,5 +1,7 @@
1
- function defineConfig(config) {
2
- return config;
3
- }
4
-
5
- export { defineConfig };
1
+ export { defineConfig } from './module.mjs';
2
+ import 'node:fs';
3
+ import '@nuxt/kit';
4
+ import 'defu';
5
+ import 'pathe';
6
+ import 'node:fs/promises';
7
+ import 'scule';
package/dist/module.d.mts CHANGED
@@ -1,6 +1,141 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { BundledLanguage, LanguageRegistration, BundledTheme, ThemeRegistrationAny } from 'shiki';
3
- import { MdcThemeOptions } from '../dist/runtime/highlighter/types.js';
2
+ import { BuiltinTheme, Highlighter as Highlighter$1, ShikiTransformer, HighlighterCore, BundledLanguage, LanguageRegistration, BundledTheme, ThemeRegistrationAny } from 'shiki';
3
+ import { Options } from 'remark-rehype';
4
+ import { Processor } from 'unified';
5
+ import { ElementContent as ElementContent$1 } from 'hast';
6
+
7
+ type MDCText = {
8
+ type: 'text';
9
+ value: string;
10
+ };
11
+ type MDCComment = {
12
+ type: 'comment';
13
+ value: string;
14
+ };
15
+ type MDCElement = {
16
+ type: 'element';
17
+ tag: string;
18
+ props: Record<string, any> | undefined;
19
+ children: Array<MDCElement | MDCText | MDCComment>;
20
+ };
21
+ type MDCNode = MDCElement | MDCText | MDCComment;
22
+ type MDCRoot = {
23
+ type: 'root';
24
+ children: Array<MDCNode>;
25
+ };
26
+ interface MDCData extends Record<string, any> {
27
+ title: string;
28
+ description: string;
29
+ }
30
+
31
+ type MdcThemeOptions = BuiltinTheme | string | Record<string, BuiltinTheme | string>;
32
+ interface HighlighterOptions {
33
+ highlights?: number[];
34
+ meta?: string;
35
+ }
36
+ interface HighlightResult {
37
+ tree: ElementContent$1[];
38
+ className?: string;
39
+ style?: string;
40
+ inlineStyle?: string;
41
+ }
42
+ type Highlighter = (code: string, lang: string, theme: MdcThemeOptions, options: Partial<HighlighterOptions>) => Promise<HighlightResult>;
43
+ interface RehypeHighlightOption {
44
+ theme?: MdcThemeOptions;
45
+ highlighter?: Highlighter;
46
+ }
47
+
48
+ type Awaitable<T> = T | Promise<T>;
49
+ interface MdcConfig {
50
+ /**
51
+ * Hooks for the unified markdown pipeline
52
+ */
53
+ unified?: {
54
+ /**
55
+ * Custom setup for unified processor before other plugins
56
+ */
57
+ pre?: (processor: Processor) => Awaitable<void | Processor>;
58
+ /**
59
+ * Custom setup for unified processor after remark but before rehype
60
+ */
61
+ remark?: (processor: Processor) => Awaitable<void | Processor>;
62
+ /**
63
+ * Custom setup for unified processor after rehype
64
+ */
65
+ rehype?: (processor: Processor) => Awaitable<void | Processor>;
66
+ /**
67
+ * Custom setup for unified processor after all plugins
68
+ */
69
+ post?: (processor: Processor) => Awaitable<void | Processor>;
70
+ };
71
+ /**
72
+ * Custom hightlighter, available when `highlighter` is set to `custom`
73
+ */
74
+ highlighter?: Highlighter$1;
75
+ /**
76
+ * Hooks for shiki
77
+ */
78
+ shiki?: {
79
+ /**
80
+ * Get transformers for shiki
81
+ */
82
+ transformers?: ShikiTransformer[] | ((code: string, lang: string, theme: MdcThemeOptions, options: Partial<HighlighterOptions>) => Awaitable<ShikiTransformer[]>);
83
+ /**
84
+ * Custom setup for shiki instance, only called once on server or client
85
+ */
86
+ setup?: (highlighter: HighlighterCore) => Awaitable<void>;
87
+ };
88
+ }
89
+
90
+ interface TocLink {
91
+ id: string;
92
+ text: string;
93
+ depth: number;
94
+ children?: TocLink[];
95
+ }
96
+ interface Toc {
97
+ title: string;
98
+ depth: number;
99
+ searchDepth: number;
100
+ links: TocLink[];
101
+ }
102
+
103
+ interface RemarkPlugin {
104
+ instance?: any;
105
+ options?: Array<any> | Record<string, any>;
106
+ }
107
+ interface RehypePlugin {
108
+ instance?: any;
109
+ options?: Array<any> | Record<string, any>;
110
+ }
111
+ interface MDCParseOptions {
112
+ remark?: {
113
+ plugins?: Record<string, false | RemarkPlugin>;
114
+ };
115
+ rehype?: {
116
+ options?: Options;
117
+ plugins?: Record<string, false | RehypePlugin>;
118
+ };
119
+ highlight?: RehypeHighlightOption | false;
120
+ toc?: {
121
+ /**
122
+ * Maximum heading depth to include in the table of contents.
123
+ */
124
+ depth?: number;
125
+ searchDepth?: number;
126
+ };
127
+ keepComments?: boolean;
128
+ /**
129
+ * Inline mdc.config.ts
130
+ */
131
+ configs?: MdcConfig[];
132
+ }
133
+ interface MDCParserResult {
134
+ data: MDCData;
135
+ body: MDCRoot;
136
+ excerpt: MDCRoot | undefined;
137
+ toc: Toc | undefined;
138
+ }
4
139
 
5
140
  interface UnistPlugin {
6
141
  src?: string;
@@ -69,6 +204,370 @@ interface ModuleOptions {
69
204
  };
70
205
  }
71
206
 
207
+ /**
208
+ * Info associated with nodes by the ecosystem.
209
+ *
210
+ * This space is guaranteed to never be specified by unist or specifications
211
+ * implementing unist.
212
+ * But you can use it in utilities and plugins to store data.
213
+ *
214
+ * This type can be augmented to register custom data.
215
+ * For example:
216
+ *
217
+ * ```ts
218
+ * declare module 'unist' {
219
+ * interface Data {
220
+ * // `someNode.data.myId` is typed as `number | undefined`
221
+ * myId?: number | undefined
222
+ * }
223
+ * }
224
+ * ```
225
+ */
226
+ interface Data$1 {
227
+ }
228
+ /**
229
+ * One place in a source file.
230
+ */
231
+ interface Point {
232
+ /**
233
+ * Line in a source file (1-indexed integer).
234
+ */
235
+ line: number;
236
+ /**
237
+ * Column in a source file (1-indexed integer).
238
+ */
239
+ column: number;
240
+ /**
241
+ * Character in a source file (0-indexed integer).
242
+ */
243
+ offset?: number | undefined;
244
+ }
245
+ /**
246
+ * Position of a node in a source document.
247
+ *
248
+ * A position is a range between two points.
249
+ */
250
+ interface Position {
251
+ /**
252
+ * Place of the first character of the parsed source region.
253
+ */
254
+ start: Point;
255
+ /**
256
+ * Place of the first character after the parsed source region.
257
+ */
258
+ end: Point;
259
+ }
260
+ /**
261
+ * Abstract unist node that contains the smallest possible value.
262
+ *
263
+ * This interface is supposed to be extended.
264
+ *
265
+ * For example, in HTML, a `text` node is a leaf that contains text.
266
+ */
267
+ interface Literal$1 extends Node$1 {
268
+ /**
269
+ * Plain value.
270
+ */
271
+ value: unknown;
272
+ }
273
+ /**
274
+ * Abstract unist node.
275
+ *
276
+ * The syntactic unit in unist syntax trees are called nodes.
277
+ *
278
+ * This interface is supposed to be extended.
279
+ * If you can use {@link Literal} or {@link Parent}, you should.
280
+ * But for example in markdown, a `thematicBreak` (`***`), is neither literal
281
+ * nor parent, but still a node.
282
+ */
283
+ interface Node$1 {
284
+ /**
285
+ * Node type.
286
+ */
287
+ type: string;
288
+ /**
289
+ * Info from the ecosystem.
290
+ */
291
+ data?: Data$1 | undefined;
292
+ /**
293
+ * Position of a node in a source document.
294
+ *
295
+ * Nodes that are generated (not in the original source document) must not
296
+ * have a position.
297
+ */
298
+ position?: Position | undefined;
299
+ }
300
+ /**
301
+ * Abstract unist node that contains other nodes (*children*).
302
+ *
303
+ * This interface is supposed to be extended.
304
+ *
305
+ * For example, in XML, an element is a parent of different things, such as
306
+ * comments, text, and further elements.
307
+ */
308
+ interface Parent$1 extends Node$1 {
309
+ /**
310
+ * List of children.
311
+ */
312
+ children: Node$1[];
313
+ }
314
+
315
+ /**
316
+ * Info associated with hast nodes by the ecosystem.
317
+ *
318
+ * This space is guaranteed to never be specified by unist or hast.
319
+ * But you can use it in utilities and plugins to store data.
320
+ *
321
+ * This type can be augmented to register custom data.
322
+ * For example:
323
+ *
324
+ * ```ts
325
+ * declare module 'hast' {
326
+ * interface Data {
327
+ * // `someNode.data.myId` is typed as `number | undefined`
328
+ * myId?: number | undefined
329
+ * }
330
+ * }
331
+ * ```
332
+ */
333
+ interface Data extends Data$1 {
334
+ }
335
+ /**
336
+ * Info associated with an element.
337
+ */
338
+ interface Properties {
339
+ [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
340
+ }
341
+ /**
342
+ * Union of registered hast nodes that can occur in {@link Element}.
343
+ *
344
+ * To register mote custom hast nodes, add them to {@link ElementContentMap}.
345
+ * They will be automatically added here.
346
+ */
347
+ type ElementContent = ElementContentMap[keyof ElementContentMap];
348
+ /**
349
+ * Registry of all hast nodes that can occur as children of {@link Element}.
350
+ *
351
+ * For a union of all {@link Element} children, see {@link ElementContent}.
352
+ */
353
+ interface ElementContentMap {
354
+ comment: Comment;
355
+ element: Element;
356
+ text: Text;
357
+ }
358
+ /**
359
+ * Union of registered hast nodes that can occur in {@link Root}.
360
+ *
361
+ * To register custom hast nodes, add them to {@link RootContentMap}.
362
+ * They will be automatically added here.
363
+ */
364
+ type RootContent = RootContentMap[keyof RootContentMap];
365
+ /**
366
+ * Registry of all hast nodes that can occur as children of {@link Root}.
367
+ *
368
+ * > 👉 **Note**: {@link Root} does not need to be an entire document.
369
+ * > it can also be a fragment.
370
+ *
371
+ * For a union of all {@link Root} children, see {@link RootContent}.
372
+ */
373
+ interface RootContentMap {
374
+ comment: Comment;
375
+ doctype: Doctype;
376
+ element: Element;
377
+ text: Text;
378
+ }
379
+ /**
380
+ * Union of registered hast nodes that can occur in {@link Root}.
381
+ *
382
+ * @deprecated Use {@link RootContent} instead.
383
+ */
384
+ type Content = RootContent;
385
+ /**
386
+ * Union of registered hast literals.
387
+ *
388
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
389
+ * places where relevant.
390
+ * They will be automatically added here.
391
+ */
392
+ type Literals = Extract<Nodes, Literal$1>;
393
+ /**
394
+ * Union of registered hast nodes.
395
+ *
396
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
397
+ * places where relevant.
398
+ * They will be automatically added here.
399
+ */
400
+ type Nodes = Root | RootContent;
401
+ /**
402
+ * Union of registered hast parents.
403
+ *
404
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
405
+ * places where relevant.
406
+ * They will be automatically added here.
407
+ */
408
+ type Parents = Extract<Nodes, Parent$1>;
409
+ /**
410
+ * Abstract hast node.
411
+ *
412
+ * This interface is supposed to be extended.
413
+ * If you can use {@link Literal} or {@link Parent}, you should.
414
+ * But for example in HTML, a `Doctype` is neither literal nor parent, but
415
+ * still a node.
416
+ *
417
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
418
+ * places where relevant (such as {@link ElementContentMap}).
419
+ *
420
+ * For a union of all registered hast nodes, see {@link Nodes}.
421
+ */
422
+ interface Node extends Node$1 {
423
+ /**
424
+ * Info from the ecosystem.
425
+ */
426
+ data?: Data | undefined;
427
+ }
428
+ /**
429
+ * Abstract hast node that contains the smallest possible value.
430
+ *
431
+ * This interface is supposed to be extended if you make custom hast nodes.
432
+ *
433
+ * For a union of all registered hast literals, see {@link Literals}.
434
+ */
435
+ interface Literal extends Node {
436
+ /**
437
+ * Plain-text value.
438
+ */
439
+ value: string;
440
+ }
441
+ /**
442
+ * Abstract hast node that contains other hast nodes (*children*).
443
+ *
444
+ * This interface is supposed to be extended if you make custom hast nodes.
445
+ *
446
+ * For a union of all registered hast parents, see {@link Parents}.
447
+ */
448
+ interface Parent extends Node {
449
+ /**
450
+ * List of children.
451
+ */
452
+ children: RootContent[];
453
+ }
454
+ /**
455
+ * HTML comment.
456
+ */
457
+ interface Comment extends Literal {
458
+ /**
459
+ * Node type of HTML comments in hast.
460
+ */
461
+ type: 'comment';
462
+ /**
463
+ * Data associated with the comment.
464
+ */
465
+ data?: CommentData | undefined;
466
+ }
467
+ /**
468
+ * Info associated with hast comments by the ecosystem.
469
+ */
470
+ interface CommentData extends Data {
471
+ }
472
+ /**
473
+ * HTML document type.
474
+ */
475
+ interface Doctype extends Node$1 {
476
+ /**
477
+ * Node type of HTML document types in hast.
478
+ */
479
+ type: 'doctype';
480
+ /**
481
+ * Data associated with the doctype.
482
+ */
483
+ data?: DoctypeData | undefined;
484
+ }
485
+ /**
486
+ * Info associated with hast doctypes by the ecosystem.
487
+ */
488
+ interface DoctypeData extends Data {
489
+ }
490
+ /**
491
+ * HTML element.
492
+ */
493
+ interface Element extends Parent {
494
+ /**
495
+ * Node type of elements.
496
+ */
497
+ type: 'element';
498
+ /**
499
+ * Tag name (such as `'body'`) of the element.
500
+ */
501
+ tagName: string;
502
+ /**
503
+ * Info associated with the element.
504
+ */
505
+ properties: Properties;
506
+ /**
507
+ * Children of element.
508
+ */
509
+ children: ElementContent[];
510
+ /**
511
+ * When the `tagName` field is `'template'`, a `content` field can be
512
+ * present.
513
+ */
514
+ content?: Root | undefined;
515
+ /**
516
+ * Data associated with the element.
517
+ */
518
+ data?: ElementData | undefined;
519
+ }
520
+ /**
521
+ * Info associated with hast elements by the ecosystem.
522
+ */
523
+ interface ElementData extends Data {
524
+ }
525
+ /**
526
+ * Document fragment or a whole document.
527
+ *
528
+ * Should be used as the root of a tree and must not be used as a child.
529
+ *
530
+ * Can also be used as the value for the content field on a `'template'` element.
531
+ */
532
+ interface Root extends Parent {
533
+ /**
534
+ * Node type of hast root.
535
+ */
536
+ type: 'root';
537
+ /**
538
+ * Children of root.
539
+ */
540
+ children: RootContent[];
541
+ /**
542
+ * Data associated with the hast root.
543
+ */
544
+ data?: RootData | undefined;
545
+ }
546
+ /**
547
+ * Info associated with hast root nodes by the ecosystem.
548
+ */
549
+ interface RootData extends Data {
550
+ }
551
+ /**
552
+ * HTML character data (plain text).
553
+ */
554
+ interface Text extends Literal {
555
+ /**
556
+ * Node type of HTML character data (plain text) in hast.
557
+ */
558
+ type: 'text';
559
+ /**
560
+ * Data associated with the text.
561
+ */
562
+ data?: TextData | undefined;
563
+ }
564
+ /**
565
+ * Info associated with hast texts by the ecosystem.
566
+ */
567
+ interface TextData extends Data {
568
+ }
569
+
570
+ declare function defineConfig(config: MdcConfig): MdcConfig;
72
571
  declare const DefaultHighlightLangs: BundledLanguage[];
73
572
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
74
573
 
@@ -101,4 +600,4 @@ declare module '@nuxt/schema' {
101
600
  }
102
601
  }
103
602
 
104
- export { DefaultHighlightLangs, _default as default };
603
+ export { type Awaitable, type Comment, type CommentData, type Content, type Data, DefaultHighlightLangs, type Doctype, type DoctypeData, type Element, type ElementContent, type ElementContentMap, type ElementData, type HighlightResult, type Highlighter, type HighlighterOptions, type Literal, type Literals, type MDCComment, type MDCData, type MDCElement, type MDCNode, type MDCParseOptions, type MDCParserResult, type MDCRoot, type MDCText, type MdcConfig, type MdcThemeOptions, type ModuleOptions, type Node, type Nodes, type Parent, type Parents, type Properties, type RehypeHighlightOption, type RehypePlugin, type RemarkPlugin, type Root, type RootContent, type RootContentMap, type RootData, type Text, type TextData, type Toc, type TocLink, type UnistPlugin, _default as default, defineConfig };