@kekonic/diagrams-remark 1.0.0-rc.4

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kekonic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # `@kekonic/diagrams-remark`
2
+
3
+ Render fenced `kdiagrams` blocks to static, accessible SVG in Remark and Unified pipelines.
4
+
5
+ ```ts
6
+ import remarkKDiagram from "@kekonic/diagrams-remark";
7
+ import remarkParse from "remark-parse";
8
+ import remarkRehype from "remark-rehype";
9
+ import rehypeStringify from "rehype-stringify";
10
+ import { unified } from "unified";
11
+
12
+ const html = await unified()
13
+ .use(remarkParse)
14
+ .use(remarkKDiagram)
15
+ .use(remarkRehype)
16
+ .use(rehypeStringify)
17
+ .process(markdown);
18
+ ```
19
+
20
+ The plugin converts renderer-generated SVG into HAST and passes it through Unified's standard tree
21
+ bridge. It does not emit a raw HTML node or require `rehype-raw`. Diagnostics are attached to the
22
+ VFile with their corresponding Markdown positions.
@@ -0,0 +1,1049 @@
1
+ import { Diagnostic, RenderOptions } from "@kekonic/diagrams";
2
+ import { Plugin } from "unified";
3
+
4
+ //#region ../../node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts
5
+ // ## Interfaces
6
+ /**
7
+ * Info associated with nodes by the ecosystem.
8
+ *
9
+ * This space is guaranteed to never be specified by unist or specifications
10
+ * implementing unist.
11
+ * But you can use it in utilities and plugins to store data.
12
+ *
13
+ * This type can be augmented to register custom data.
14
+ * For example:
15
+ *
16
+ * ```ts
17
+ * declare module 'unist' {
18
+ * interface Data {
19
+ * // `someNode.data.myId` is typed as `number | undefined`
20
+ * myId?: number | undefined
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ interface Data$1 {}
26
+ /**
27
+ * One place in a source file.
28
+ */
29
+ interface Point {
30
+ /**
31
+ * Line in a source file (1-indexed integer).
32
+ */
33
+ line: number;
34
+ /**
35
+ * Column in a source file (1-indexed integer).
36
+ */
37
+ column: number;
38
+ /**
39
+ * Character in a source file (0-indexed integer).
40
+ */
41
+ offset?: number | undefined;
42
+ }
43
+ /**
44
+ * Position of a node in a source document.
45
+ *
46
+ * A position is a range between two points.
47
+ */
48
+ interface Position {
49
+ /**
50
+ * Place of the first character of the parsed source region.
51
+ */
52
+ start: Point;
53
+ /**
54
+ * Place of the first character after the parsed source region.
55
+ */
56
+ end: Point;
57
+ }
58
+ /**
59
+ * Abstract unist node.
60
+ *
61
+ * The syntactic unit in unist syntax trees are called nodes.
62
+ *
63
+ * This interface is supposed to be extended.
64
+ * If you can use {@link Literal} or {@link Parent}, you should.
65
+ * But for example in markdown, a `thematicBreak` (`***`), is neither literal
66
+ * nor parent, but still a node.
67
+ */
68
+ interface Node$1 {
69
+ /**
70
+ * Node type.
71
+ */
72
+ type: string;
73
+ /**
74
+ * Info from the ecosystem.
75
+ */
76
+ data?: Data$1 | undefined;
77
+ /**
78
+ * Position of a node in a source document.
79
+ *
80
+ * Nodes that are generated (not in the original source document) must not
81
+ * have a position.
82
+ */
83
+ position?: Position | undefined;
84
+ }
85
+ //#endregion
86
+ //#region ../../node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts
87
+ // ## Enumeration
88
+ /**
89
+ * How phrasing content is aligned
90
+ * ({@link https://drafts.csswg.org/css-text/ | [CSSTEXT]}).
91
+ *
92
+ * * `'left'`: See the
93
+ * {@link https://drafts.csswg.org/css-text/#valdef-text-align-left | left}
94
+ * value of the `text-align` CSS property
95
+ * * `'right'`: See the
96
+ * {@link https://drafts.csswg.org/css-text/#valdef-text-align-right | right}
97
+ * value of the `text-align` CSS property
98
+ * * `'center'`: See the
99
+ * {@link https://drafts.csswg.org/css-text/#valdef-text-align-center | center}
100
+ * value of the `text-align` CSS property
101
+ * * `null`: phrasing content is aligned as defined by the host environment
102
+ *
103
+ * Used in GFM tables.
104
+ */
105
+ type AlignType = "center" | "left" | "right" | null;
106
+ /**
107
+ * Explicitness of a reference.
108
+ *
109
+ * `'shortcut'`: the reference is implicit, its identifier inferred from its
110
+ * content
111
+ * `'collapsed'`: the reference is explicit, its identifier inferred from its
112
+ * content
113
+ * `'full'`: the reference is explicit, its identifier explicitly set
114
+ */
115
+ type ReferenceType = "shortcut" | "collapsed" | "full";
116
+ // ## Mixin
117
+ /**
118
+ * Node with a fallback.
119
+ */
120
+ interface Alternative {
121
+ /**
122
+ * Equivalent content for environments that cannot represent the node as
123
+ * intended.
124
+ */
125
+ alt?: string | null | undefined;
126
+ }
127
+ /**
128
+ * Internal relation from one node to another.
129
+ *
130
+ * Whether the value of `identifier` is expected to be a unique identifier or
131
+ * not depends on the type of node including the Association.
132
+ * An example of this is that they should be unique on {@link Definition},
133
+ * whereas multiple {@link LinkReference}s can be non-unique to be associated
134
+ * with one definition.
135
+ */
136
+ interface Association {
137
+ /**
138
+ * Relation of association.
139
+ *
140
+ * `identifier` is a source value: character escapes and character
141
+ * references are not parsed.
142
+ *
143
+ * It can match another node.
144
+ *
145
+ * Its value must be normalized.
146
+ * To normalize a value, collapse markdown whitespace (`[\t\n\r ]+`) to a space,
147
+ * trim the optional initial and/or final space, and perform Unicode-aware
148
+ * case-folding.
149
+ */
150
+ identifier: string;
151
+ /**
152
+ * Relation of association, in parsed form.
153
+ *
154
+ * `label` is a `string` value: it works just like `title` on {@link Link}
155
+ * or a `lang` on {@link Code}: character escapes and character references
156
+ * are parsed.
157
+ *
158
+ * It can match another node.
159
+ */
160
+ label?: string | null | undefined;
161
+ }
162
+ /**
163
+ * Marker that is associated to another node.
164
+ */
165
+ interface Reference extends Association {
166
+ /**
167
+ * Explicitness of the reference.
168
+ */
169
+ referenceType: ReferenceType;
170
+ }
171
+ /**
172
+ * Reference to resource.
173
+ */
174
+ interface Resource {
175
+ /**
176
+ * URL to the referenced resource.
177
+ */
178
+ url: string;
179
+ /**
180
+ * Advisory information for the resource, such as would be appropriate for
181
+ * a tooltip.
182
+ */
183
+ title?: string | null | undefined;
184
+ }
185
+ // ## Interfaces
186
+ /**
187
+ * Info associated with mdast nodes by the ecosystem.
188
+ *
189
+ * This space is guaranteed to never be specified by unist or mdast.
190
+ * But you can use it in utilities and plugins to store data.
191
+ *
192
+ * This type can be augmented to register custom data.
193
+ * For example:
194
+ *
195
+ * ```ts
196
+ * declare module 'mdast' {
197
+ * interface Data {
198
+ * // `someNode.data.myId` is typed as `number | undefined`
199
+ * myId?: number | undefined
200
+ * }
201
+ * }
202
+ * ```
203
+ */
204
+ interface Data extends Data$1 {}
205
+ // ## Content maps
206
+ /**
207
+ * Union of registered mdast nodes that can occur where block content is
208
+ * expected.
209
+ *
210
+ * To register custom mdast nodes, add them to {@link BlockContentMap}.
211
+ * They will be automatically added here.
212
+ */
213
+ type BlockContent = BlockContentMap[keyof BlockContentMap];
214
+ /**
215
+ * Registry of all mdast nodes that can occur where {@link BlockContent} is
216
+ * expected.
217
+ *
218
+ * This interface can be augmented to register custom node types:
219
+ *
220
+ * ```ts
221
+ * declare module 'mdast' {
222
+ * interface BlockContentMap {
223
+ * // Allow using MDX ESM nodes defined by `remark-mdx`.
224
+ * mdxjsEsm: MdxjsEsm;
225
+ * }
226
+ * }
227
+ * ```
228
+ *
229
+ * For a union of all block content, see {@link RootContent}.
230
+ */
231
+ interface BlockContentMap {
232
+ blockquote: Blockquote;
233
+ code: Code;
234
+ heading: Heading;
235
+ html: Html;
236
+ list: List;
237
+ paragraph: Paragraph;
238
+ table: Table;
239
+ thematicBreak: ThematicBreak;
240
+ }
241
+ /**
242
+ * Union of registered mdast nodes that can occur where definition content is
243
+ * expected.
244
+ *
245
+ * To register custom mdast nodes, add them to {@link DefinitionContentMap}.
246
+ * They will be automatically added here.
247
+ */
248
+ type DefinitionContent = DefinitionContentMap[keyof DefinitionContentMap];
249
+ /**
250
+ * Registry of all mdast nodes that can occur where {@link DefinitionContent}
251
+ * is expected.
252
+ *
253
+ * This interface can be augmented to register custom node types:
254
+ *
255
+ * ```ts
256
+ * declare module 'mdast' {
257
+ * interface DefinitionContentMap {
258
+ * custom: Custom;
259
+ * }
260
+ * }
261
+ * ```
262
+ *
263
+ * For a union of all definition content, see {@link RootContent}.
264
+ */
265
+ interface DefinitionContentMap {
266
+ definition: Definition;
267
+ footnoteDefinition: FootnoteDefinition;
268
+ }
269
+ /**
270
+ * Union of registered mdast nodes that can occur where list content is
271
+ * expected.
272
+ *
273
+ * To register custom mdast nodes, add them to {@link ListContentMap}.
274
+ * They will be automatically added here.
275
+ */
276
+ type ListContent = ListContentMap[keyof ListContentMap];
277
+ /**
278
+ * Registry of all mdast nodes that can occur where {@link ListContent}
279
+ * is expected.
280
+ *
281
+ * This interface can be augmented to register custom node types:
282
+ *
283
+ * ```ts
284
+ * declare module 'mdast' {
285
+ * interface ListContentMap {
286
+ * custom: Custom;
287
+ * }
288
+ * }
289
+ * ```
290
+ *
291
+ * For a union of all list content, see {@link RootContent}.
292
+ */
293
+ interface ListContentMap {
294
+ listItem: ListItem;
295
+ }
296
+ /**
297
+ * Union of registered mdast nodes that can occur where phrasing content is
298
+ * expected.
299
+ *
300
+ * To register custom mdast nodes, add them to {@link PhrasingContentMap}.
301
+ * They will be automatically added here.
302
+ */
303
+ type PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap];
304
+ /**
305
+ * Registry of all mdast nodes that can occur where {@link PhrasingContent}
306
+ * is expected.
307
+ *
308
+ * This interface can be augmented to register custom node types:
309
+ *
310
+ * ```ts
311
+ * declare module 'mdast' {
312
+ * interface PhrasingContentMap {
313
+ * // Allow using MDX JSX (text) nodes defined by `remark-mdx`.
314
+ * mdxJsxTextElement: MDXJSXTextElement;
315
+ * }
316
+ * }
317
+ * ```
318
+ *
319
+ * For a union of all phrasing content, see {@link RootContent}.
320
+ */
321
+ interface PhrasingContentMap {
322
+ break: Break;
323
+ delete: Delete;
324
+ emphasis: Emphasis;
325
+ footnoteReference: FootnoteReference;
326
+ html: Html;
327
+ image: Image;
328
+ imageReference: ImageReference;
329
+ inlineCode: InlineCode;
330
+ link: Link;
331
+ linkReference: LinkReference;
332
+ strong: Strong;
333
+ text: Text;
334
+ }
335
+ /**
336
+ * Union of registered mdast nodes that can occur in {@link Root}.
337
+ *
338
+ * To register custom mdast nodes, add them to {@link RootContentMap}.
339
+ * They will be automatically added here.
340
+ */
341
+ type RootContent = RootContentMap[keyof RootContentMap];
342
+ /**
343
+ * Registry of all mdast nodes that can occur as children of {@link Root}.
344
+ *
345
+ * > **Note**: {@link Root} does not need to be an entire document.
346
+ * > it can also be a fragment.
347
+ *
348
+ * This interface can be augmented to register custom node types:
349
+ *
350
+ * ```ts
351
+ * declare module 'mdast' {
352
+ * interface RootContentMap {
353
+ * // Allow using toml nodes defined by `remark-frontmatter`.
354
+ * toml: TOML;
355
+ * }
356
+ * }
357
+ * ```
358
+ *
359
+ * For a union of all {@link Root} children, see {@link RootContent}.
360
+ */
361
+ interface RootContentMap {
362
+ blockquote: Blockquote;
363
+ break: Break;
364
+ code: Code;
365
+ definition: Definition;
366
+ delete: Delete;
367
+ emphasis: Emphasis;
368
+ footnoteDefinition: FootnoteDefinition;
369
+ footnoteReference: FootnoteReference;
370
+ heading: Heading;
371
+ html: Html;
372
+ image: Image;
373
+ imageReference: ImageReference;
374
+ inlineCode: InlineCode;
375
+ link: Link;
376
+ linkReference: LinkReference;
377
+ list: List;
378
+ listItem: ListItem;
379
+ paragraph: Paragraph;
380
+ strong: Strong;
381
+ table: Table;
382
+ tableCell: TableCell;
383
+ tableRow: TableRow;
384
+ text: Text;
385
+ thematicBreak: ThematicBreak;
386
+ yaml: Yaml;
387
+ }
388
+ /**
389
+ * Union of registered mdast nodes that can occur where row content is
390
+ * expected.
391
+ *
392
+ * To register custom mdast nodes, add them to {@link RowContentMap}.
393
+ * They will be automatically added here.
394
+ */
395
+ type RowContent = RowContentMap[keyof RowContentMap];
396
+ /**
397
+ * Registry of all mdast nodes that can occur where {@link RowContent}
398
+ * is expected.
399
+ *
400
+ * This interface can be augmented to register custom node types:
401
+ *
402
+ * ```ts
403
+ * declare module 'mdast' {
404
+ * interface RowContentMap {
405
+ * custom: Custom;
406
+ * }
407
+ * }
408
+ * ```
409
+ *
410
+ * For a union of all row content, see {@link RootContent}.
411
+ */
412
+ interface RowContentMap {
413
+ tableCell: TableCell;
414
+ }
415
+ /**
416
+ * Union of registered mdast nodes that can occur where table content is
417
+ * expected.
418
+ *
419
+ * To register custom mdast nodes, add them to {@link TableContentMap}.
420
+ * They will be automatically added here.
421
+ */
422
+ type TableContent = TableContentMap[keyof TableContentMap];
423
+ /**
424
+ * Registry of all mdast nodes that can occur where {@link TableContent}
425
+ * is expected.
426
+ *
427
+ * This interface can be augmented to register custom node types:
428
+ *
429
+ * ```ts
430
+ * declare module 'mdast' {
431
+ * interface TableContentMap {
432
+ * custom: Custom;
433
+ * }
434
+ * }
435
+ * ```
436
+ *
437
+ * For a union of all table content, see {@link RootContent}.
438
+ */
439
+ interface TableContentMap {
440
+ tableRow: TableRow;
441
+ }
442
+ // ## Abstract nodes
443
+ /**
444
+ * Abstract mdast node that contains the smallest possible value.
445
+ *
446
+ * This interface is supposed to be extended if you make custom mdast nodes.
447
+ *
448
+ * For a union of all registered mdast literals, see {@link Literals}.
449
+ */
450
+ interface Literal extends Node {
451
+ /**
452
+ * Plain-text value.
453
+ */
454
+ value: string;
455
+ }
456
+ /**
457
+ * Abstract mdast node.
458
+ *
459
+ * This interface is supposed to be extended.
460
+ * If you can use {@link Literal} or {@link Parent}, you should.
461
+ * But for example in markdown, a thematic break (`***`) is neither literal nor
462
+ * parent, but still a node.
463
+ *
464
+ * To register custom mdast nodes, add them to {@link RootContentMap} and other
465
+ * places where relevant (such as {@link ElementContentMap}).
466
+ *
467
+ * For a union of all registered mdast nodes, see {@link Nodes}.
468
+ */
469
+ interface Node extends Node$1 {
470
+ /**
471
+ * Info from the ecosystem.
472
+ */
473
+ data?: Data | undefined;
474
+ }
475
+ /**
476
+ * Abstract mdast node that contains other mdast nodes (*children*).
477
+ *
478
+ * This interface is supposed to be extended if you make custom mdast nodes.
479
+ *
480
+ * For a union of all registered mdast parents, see {@link Parents}.
481
+ */
482
+ interface Parent extends Node {
483
+ /**
484
+ * List of children.
485
+ */
486
+ children: RootContent[];
487
+ }
488
+ // ## Concrete nodes
489
+ /**
490
+ * Markdown block quote.
491
+ */
492
+ interface Blockquote extends Parent {
493
+ /**
494
+ * Node type of mdast block quote.
495
+ */
496
+ type: "blockquote";
497
+ /**
498
+ * Children of block quote.
499
+ */
500
+ children: Array<BlockContent | DefinitionContent>;
501
+ /**
502
+ * Data associated with the mdast block quote.
503
+ */
504
+ data?: BlockquoteData | undefined;
505
+ }
506
+ /**
507
+ * Info associated with mdast block quote nodes by the ecosystem.
508
+ */
509
+ interface BlockquoteData extends Data {}
510
+ /**
511
+ * Markdown break.
512
+ */
513
+ interface Break extends Node {
514
+ /**
515
+ * Node type of mdast break.
516
+ */
517
+ type: "break";
518
+ /**
519
+ * Data associated with the mdast break.
520
+ */
521
+ data?: BreakData | undefined;
522
+ }
523
+ /**
524
+ * Info associated with mdast break nodes by the ecosystem.
525
+ */
526
+ interface BreakData extends Data {}
527
+ /**
528
+ * Markdown code (flow) (block).
529
+ */
530
+ interface Code extends Literal {
531
+ /**
532
+ * Node type of mdast code (flow).
533
+ */
534
+ type: "code";
535
+ /**
536
+ * Language of computer code being marked up.
537
+ */
538
+ lang?: string | null | undefined;
539
+ /**
540
+ * Custom information relating to the node.
541
+ *
542
+ * If the lang field is present, a meta field can be present.
543
+ */
544
+ meta?: string | null | undefined;
545
+ /**
546
+ * Data associated with the mdast code (flow).
547
+ */
548
+ data?: CodeData | undefined;
549
+ }
550
+ /**
551
+ * Info associated with mdast code (flow) (block) nodes by the ecosystem.
552
+ */
553
+ interface CodeData extends Data {}
554
+ /**
555
+ * Markdown definition.
556
+ */
557
+ interface Definition extends Node, Association, Resource {
558
+ /**
559
+ * Node type of mdast definition.
560
+ */
561
+ type: "definition";
562
+ /**
563
+ * Data associated with the mdast definition.
564
+ */
565
+ data?: DefinitionData | undefined;
566
+ }
567
+ /**
568
+ * Info associated with mdast definition nodes by the ecosystem.
569
+ */
570
+ interface DefinitionData extends Data {}
571
+ /**
572
+ * Markdown GFM delete (strikethrough).
573
+ */
574
+ interface Delete extends Parent {
575
+ /**
576
+ * Node type of mdast GFM delete.
577
+ */
578
+ type: "delete";
579
+ /**
580
+ * Children of GFM delete.
581
+ */
582
+ children: PhrasingContent[];
583
+ /**
584
+ * Data associated with the mdast GFM delete.
585
+ */
586
+ data?: DeleteData | undefined;
587
+ }
588
+ /**
589
+ * Info associated with mdast GFM delete nodes by the ecosystem.
590
+ */
591
+ interface DeleteData extends Data {}
592
+ /**
593
+ * Markdown emphasis.
594
+ */
595
+ interface Emphasis extends Parent {
596
+ /**
597
+ * Node type of mdast emphasis.
598
+ */
599
+ type: "emphasis";
600
+ /**
601
+ * Children of emphasis.
602
+ */
603
+ children: PhrasingContent[];
604
+ /**
605
+ * Data associated with the mdast emphasis.
606
+ */
607
+ data?: EmphasisData | undefined;
608
+ }
609
+ /**
610
+ * Info associated with mdast emphasis nodes by the ecosystem.
611
+ */
612
+ interface EmphasisData extends Data {}
613
+ /**
614
+ * Markdown GFM footnote definition.
615
+ */
616
+ interface FootnoteDefinition extends Parent, Association {
617
+ /**
618
+ * Node type of mdast GFM footnote definition.
619
+ */
620
+ type: "footnoteDefinition";
621
+ /**
622
+ * Children of GFM footnote definition.
623
+ */
624
+ children: Array<BlockContent | DefinitionContent>;
625
+ /**
626
+ * Data associated with the mdast GFM footnote definition.
627
+ */
628
+ data?: FootnoteDefinitionData | undefined;
629
+ }
630
+ /**
631
+ * Info associated with mdast GFM footnote definition nodes by the ecosystem.
632
+ */
633
+ interface FootnoteDefinitionData extends Data {}
634
+ /**
635
+ * Markdown GFM footnote reference.
636
+ */
637
+ interface FootnoteReference extends Association, Node {
638
+ /**
639
+ * Node type of mdast GFM footnote reference.
640
+ */
641
+ type: "footnoteReference";
642
+ /**
643
+ * Data associated with the mdast GFM footnote reference.
644
+ */
645
+ data?: FootnoteReferenceData | undefined;
646
+ }
647
+ /**
648
+ * Info associated with mdast GFM footnote reference nodes by the ecosystem.
649
+ */
650
+ interface FootnoteReferenceData extends Data {}
651
+ /**
652
+ * Markdown heading.
653
+ */
654
+ interface Heading extends Parent {
655
+ /**
656
+ * Node type of mdast heading.
657
+ */
658
+ type: "heading";
659
+ /**
660
+ * Heading rank.
661
+ *
662
+ * A value of `1` is said to be the highest rank and `6` the lowest.
663
+ */
664
+ depth: 1 | 2 | 3 | 4 | 5 | 6;
665
+ /**
666
+ * Children of heading.
667
+ */
668
+ children: PhrasingContent[];
669
+ /**
670
+ * Data associated with the mdast heading.
671
+ */
672
+ data?: HeadingData | undefined;
673
+ }
674
+ /**
675
+ * Info associated with mdast heading nodes by the ecosystem.
676
+ */
677
+ interface HeadingData extends Data {}
678
+ /**
679
+ * Markdown HTML.
680
+ */
681
+ interface Html extends Literal {
682
+ /**
683
+ * Node type of mdast HTML.
684
+ */
685
+ type: "html";
686
+ /**
687
+ * Data associated with the mdast HTML.
688
+ */
689
+ data?: HtmlData | undefined;
690
+ }
691
+ /**
692
+ * Info associated with mdast HTML nodes by the ecosystem.
693
+ */
694
+ interface HtmlData extends Data {}
695
+ /**
696
+ * Markdown image.
697
+ */
698
+ interface Image extends Alternative, Node, Resource {
699
+ /**
700
+ * Node type of mdast image.
701
+ */
702
+ type: "image";
703
+ /**
704
+ * Data associated with the mdast image.
705
+ */
706
+ data?: ImageData | undefined;
707
+ }
708
+ /**
709
+ * Info associated with mdast image nodes by the ecosystem.
710
+ */
711
+ interface ImageData extends Data {}
712
+ /**
713
+ * Markdown image reference.
714
+ */
715
+ interface ImageReference extends Alternative, Node, Reference {
716
+ /**
717
+ * Node type of mdast image reference.
718
+ */
719
+ type: "imageReference";
720
+ /**
721
+ * Data associated with the mdast image reference.
722
+ */
723
+ data?: ImageReferenceData | undefined;
724
+ }
725
+ /**
726
+ * Info associated with mdast image reference nodes by the ecosystem.
727
+ */
728
+ interface ImageReferenceData extends Data {}
729
+ /**
730
+ * Markdown code (text) (inline).
731
+ */
732
+ interface InlineCode extends Literal {
733
+ /**
734
+ * Node type of mdast code (text).
735
+ */
736
+ type: "inlineCode";
737
+ /**
738
+ * Data associated with the mdast code (text).
739
+ */
740
+ data?: InlineCodeData | undefined;
741
+ }
742
+ /**
743
+ * Info associated with mdast code (text) (inline) nodes by the ecosystem.
744
+ */
745
+ interface InlineCodeData extends Data {}
746
+ /**
747
+ * Markdown link.
748
+ */
749
+ interface Link extends Parent, Resource {
750
+ /**
751
+ * Node type of mdast link.
752
+ */
753
+ type: "link";
754
+ /**
755
+ * Children of link.
756
+ */
757
+ children: PhrasingContent[];
758
+ /**
759
+ * Data associated with the mdast link.
760
+ */
761
+ data?: LinkData | undefined;
762
+ }
763
+ /**
764
+ * Info associated with mdast link nodes by the ecosystem.
765
+ */
766
+ interface LinkData extends Data {}
767
+ /**
768
+ * Markdown link reference.
769
+ */
770
+ interface LinkReference extends Parent, Reference {
771
+ /**
772
+ * Node type of mdast link reference.
773
+ */
774
+ type: "linkReference";
775
+ /**
776
+ * Children of link reference.
777
+ */
778
+ children: PhrasingContent[];
779
+ /**
780
+ * Data associated with the mdast link reference.
781
+ */
782
+ data?: LinkReferenceData | undefined;
783
+ }
784
+ /**
785
+ * Info associated with mdast link reference nodes by the ecosystem.
786
+ */
787
+ interface LinkReferenceData extends Data {}
788
+ /**
789
+ * Markdown list.
790
+ */
791
+ interface List extends Parent {
792
+ /**
793
+ * Node type of mdast list.
794
+ */
795
+ type: "list";
796
+ /**
797
+ * Whether the items have been intentionally ordered (when `true`), or that
798
+ * the order of items is not important (when `false` or not present).
799
+ */
800
+ ordered?: boolean | null | undefined;
801
+ /**
802
+ * The starting number of the list, when the `ordered` field is `true`.
803
+ */
804
+ start?: number | null | undefined;
805
+ /**
806
+ * Whether one or more of the children are separated with a blank line from
807
+ * its siblings (when `true`), or not (when `false` or not present).
808
+ */
809
+ spread?: boolean | null | undefined;
810
+ /**
811
+ * Children of list.
812
+ */
813
+ children: ListContent[];
814
+ /**
815
+ * Data associated with the mdast list.
816
+ */
817
+ data?: ListData | undefined;
818
+ }
819
+ /**
820
+ * Info associated with mdast list nodes by the ecosystem.
821
+ */
822
+ interface ListData extends Data {}
823
+ /**
824
+ * Markdown list item.
825
+ */
826
+ interface ListItem extends Parent {
827
+ /**
828
+ * Node type of mdast list item.
829
+ */
830
+ type: "listItem";
831
+ /**
832
+ * Whether the item is a tasklist item (when `boolean`).
833
+ *
834
+ * When `true`, the item is complete.
835
+ * When `false`, the item is incomplete.
836
+ */
837
+ checked?: boolean | null | undefined;
838
+ /**
839
+ * Whether one or more of the children are separated with a blank line from
840
+ * its siblings (when `true`), or not (when `false` or not present).
841
+ */
842
+ spread?: boolean | null | undefined;
843
+ /**
844
+ * Children of list item.
845
+ */
846
+ children: Array<BlockContent | DefinitionContent>;
847
+ /**
848
+ * Data associated with the mdast list item.
849
+ */
850
+ data?: ListItemData | undefined;
851
+ }
852
+ /**
853
+ * Info associated with mdast list item nodes by the ecosystem.
854
+ */
855
+ interface ListItemData extends Data {}
856
+ /**
857
+ * Markdown paragraph.
858
+ */
859
+ interface Paragraph extends Parent {
860
+ /**
861
+ * Node type of mdast paragraph.
862
+ */
863
+ type: "paragraph";
864
+ /**
865
+ * Children of paragraph.
866
+ */
867
+ children: PhrasingContent[];
868
+ /**
869
+ * Data associated with the mdast paragraph.
870
+ */
871
+ data?: ParagraphData | undefined;
872
+ }
873
+ /**
874
+ * Info associated with mdast paragraph nodes by the ecosystem.
875
+ */
876
+ interface ParagraphData extends Data {}
877
+ /**
878
+ * Document fragment or a whole document.
879
+ *
880
+ * Should be used as the root of a tree and must not be used as a child.
881
+ */
882
+ interface Root extends Parent {
883
+ /**
884
+ * Node type of mdast root.
885
+ */
886
+ type: "root";
887
+ /**
888
+ * Data associated with the mdast root.
889
+ */
890
+ data?: RootData | undefined;
891
+ }
892
+ /**
893
+ * Info associated with mdast root nodes by the ecosystem.
894
+ */
895
+ interface RootData extends Data {}
896
+ /**
897
+ * Markdown strong.
898
+ */
899
+ interface Strong extends Parent {
900
+ /**
901
+ * Node type of mdast strong.
902
+ */
903
+ type: "strong";
904
+ /**
905
+ * Children of strong.
906
+ */
907
+ children: PhrasingContent[];
908
+ /**
909
+ * Data associated with the mdast strong.
910
+ */
911
+ data?: StrongData | undefined;
912
+ }
913
+ /**
914
+ * Info associated with mdast strong nodes by the ecosystem.
915
+ */
916
+ interface StrongData extends Data {}
917
+ /**
918
+ * Markdown GFM table.
919
+ */
920
+ interface Table extends Parent {
921
+ /**
922
+ * Node type of mdast GFM table.
923
+ */
924
+ type: "table";
925
+ /**
926
+ * How cells in columns are aligned.
927
+ */
928
+ align?: AlignType[] | null | undefined;
929
+ /**
930
+ * Children of GFM table.
931
+ */
932
+ children: TableContent[];
933
+ /**
934
+ * Data associated with the mdast GFM table.
935
+ */
936
+ data?: TableData | undefined;
937
+ }
938
+ /**
939
+ * Info associated with mdast GFM table nodes by the ecosystem.
940
+ */
941
+ interface TableData extends Data {}
942
+ /**
943
+ * Markdown GFM table row.
944
+ */
945
+ interface TableRow extends Parent {
946
+ /**
947
+ * Node type of mdast GFM table row.
948
+ */
949
+ type: "tableRow";
950
+ /**
951
+ * Children of GFM table row.
952
+ */
953
+ children: RowContent[];
954
+ /**
955
+ * Data associated with the mdast GFM table row.
956
+ */
957
+ data?: TableRowData | undefined;
958
+ }
959
+ /**
960
+ * Info associated with mdast GFM table row nodes by the ecosystem.
961
+ */
962
+ interface TableRowData extends Data {}
963
+ /**
964
+ * Markdown GFM table cell.
965
+ */
966
+ interface TableCell extends Parent {
967
+ /**
968
+ * Node type of mdast GFM table cell.
969
+ */
970
+ type: "tableCell";
971
+ /**
972
+ * Children of GFM table cell.
973
+ */
974
+ children: PhrasingContent[];
975
+ /**
976
+ * Data associated with the mdast GFM table cell.
977
+ */
978
+ data?: TableCellData | undefined;
979
+ }
980
+ /**
981
+ * Info associated with mdast GFM table cell nodes by the ecosystem.
982
+ */
983
+ interface TableCellData extends Data {}
984
+ /**
985
+ * Markdown text.
986
+ */
987
+ interface Text extends Literal {
988
+ /**
989
+ * Node type of mdast text.
990
+ */
991
+ type: "text";
992
+ /**
993
+ * Data associated with the mdast text.
994
+ */
995
+ data?: TextData | undefined;
996
+ }
997
+ /**
998
+ * Info associated with mdast text nodes by the ecosystem.
999
+ */
1000
+ interface TextData extends Data {}
1001
+ /**
1002
+ * Markdown thematic break (horizontal rule).
1003
+ */
1004
+ interface ThematicBreak extends Node {
1005
+ /**
1006
+ * Node type of mdast thematic break.
1007
+ */
1008
+ type: "thematicBreak";
1009
+ /**
1010
+ * Data associated with the mdast thematic break.
1011
+ */
1012
+ data?: ThematicBreakData | undefined;
1013
+ }
1014
+ /**
1015
+ * Info associated with mdast thematic break nodes by the ecosystem.
1016
+ */
1017
+ interface ThematicBreakData extends Data {}
1018
+ /**
1019
+ * Markdown YAML.
1020
+ */
1021
+ interface Yaml extends Literal {
1022
+ /**
1023
+ * Node type of mdast YAML.
1024
+ */
1025
+ type: "yaml";
1026
+ /**
1027
+ * Data associated with the mdast YAML.
1028
+ */
1029
+ data?: YamlData | undefined;
1030
+ }
1031
+ /**
1032
+ * Info associated with mdast YAML nodes by the ecosystem.
1033
+ */
1034
+ interface YamlData extends Data {}
1035
+ //#endregion
1036
+ //#region src/index.d.ts
1037
+ type KDiagramRemarkDiagnostic = Diagnostic & {
1038
+ markdownLine: number;
1039
+ markdownEndLine: number;
1040
+ };
1041
+ type KDiagramRemarkOptions = {
1042
+ className?: string;
1043
+ renderOptions?: RenderOptions;
1044
+ onDiagnostic?: (diagnostic: KDiagramRemarkDiagnostic) => void;
1045
+ };
1046
+ declare const remarkKDiagram: Plugin<[KDiagramRemarkOptions?], Root>;
1047
+ //#endregion
1048
+ export { KDiagramRemarkDiagnostic, KDiagramRemarkOptions, remarkKDiagram as default, remarkKDiagram };
1049
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,69 @@
1
+ import { formatKDiagramBuildError, offsetKDiagramDiagnostic, renderKDiagramForBuild } from "@kekonic/diagrams-build";
2
+ import { fromHtml } from "hast-util-from-html";
3
+ import { visit } from "unist-util-visit";
4
+ //#region src/index.ts
5
+ const remarkKDiagram = function remarkKDiagram(options = {}) {
6
+ return async (tree, file) => {
7
+ const fences = [];
8
+ visit(tree, "code", (node) => {
9
+ if (node.lang?.toLowerCase() === "kdiagram") fences.push(node);
10
+ });
11
+ await Promise.all(fences.map(async (node) => {
12
+ const result = await renderKDiagramForBuild(node.value, { renderOptions: options.renderOptions });
13
+ const diagnostics = result.diagnostics.map((diagnostic) => mapDiagnostic(node, diagnostic));
14
+ for (const diagnostic of diagnostics) {
15
+ options.onDiagnostic?.(diagnostic);
16
+ file.message(diagnostic.message, {
17
+ start: {
18
+ line: diagnostic.markdownLine,
19
+ column: diagnostic.range?.start.column ?? 1
20
+ },
21
+ end: {
22
+ line: diagnostic.markdownEndLine,
23
+ column: diagnostic.range?.end.column ?? 1
24
+ }
25
+ }).ruleId = diagnostic.code;
26
+ }
27
+ if (result.svg) {
28
+ const svgTree = fromHtml(result.svg, { fragment: true });
29
+ node.data = {
30
+ ...node.data,
31
+ hName: "figure",
32
+ hProperties: { className: [options.className ?? "k-diagram"] },
33
+ hChildren: svgTree.children
34
+ };
35
+ return;
36
+ }
37
+ const message = formatKDiagramBuildError(diagnostics);
38
+ node.lang = void 0;
39
+ node.meta = void 0;
40
+ node.value = message;
41
+ node.data = {
42
+ ...node.data,
43
+ hName: "pre",
44
+ hProperties: { className: ["kdiagram-error"] },
45
+ hChildren: [{
46
+ type: "element",
47
+ tagName: "code",
48
+ properties: {},
49
+ children: [{
50
+ type: "text",
51
+ value: message
52
+ }]
53
+ }]
54
+ };
55
+ }));
56
+ };
57
+ };
58
+ function mapDiagnostic(node, diagnostic) {
59
+ const mapped = offsetKDiagramDiagnostic(diagnostic, (node.position?.start.line ?? 1) + 1);
60
+ return {
61
+ ...diagnostic,
62
+ markdownLine: mapped.hostLine,
63
+ markdownEndLine: mapped.hostEndLine
64
+ };
65
+ }
66
+ //#endregion
67
+ export { remarkKDiagram as default, remarkKDiagram };
68
+
69
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Diagnostic, RenderOptions } from \"@kekonic/diagrams\";\nimport {\n formatKDiagramBuildError,\n offsetKDiagramDiagnostic,\n renderKDiagramForBuild,\n} from \"@kekonic/diagrams-build\";\nimport { fromHtml } from \"hast-util-from-html\";\nimport type { ElementContent } from \"hast\";\nimport type { Code, Root } from \"mdast\";\nimport type { Plugin } from \"unified\";\nimport { visit } from \"unist-util-visit\";\n\nexport type KDiagramRemarkDiagnostic = Diagnostic & {\n markdownLine: number;\n markdownEndLine: number;\n};\n\nexport type KDiagramRemarkOptions = {\n className?: string;\n renderOptions?: RenderOptions;\n onDiagnostic?: (diagnostic: KDiagramRemarkDiagnostic) => void;\n};\n\ntype EmbeddedHastData = {\n hName: string;\n hProperties: { className: string[] };\n hChildren: ElementContent[];\n};\n\nconst remarkKDiagram: Plugin<[KDiagramRemarkOptions?], Root> = function remarkKDiagram(\n options = {},\n) {\n return async (tree, file) => {\n const fences: Code[] = [];\n visit(tree, \"code\", (node) => {\n if (node.lang?.toLowerCase() === \"kdiagram\") fences.push(node);\n });\n\n await Promise.all(\n fences.map(async (node) => {\n const result = await renderKDiagramForBuild(node.value, {\n renderOptions: options.renderOptions,\n });\n const diagnostics = result.diagnostics.map((diagnostic) => mapDiagnostic(node, diagnostic));\n for (const diagnostic of diagnostics) {\n options.onDiagnostic?.(diagnostic);\n file.message(diagnostic.message, {\n start: { line: diagnostic.markdownLine, column: diagnostic.range?.start.column ?? 1 },\n end: { line: diagnostic.markdownEndLine, column: diagnostic.range?.end.column ?? 1 },\n }).ruleId = diagnostic.code;\n }\n\n if (result.svg) {\n const svgTree = fromHtml(result.svg, { fragment: true });\n node.data = {\n ...node.data,\n hName: \"figure\",\n hProperties: { className: [options.className ?? \"k-diagram\"] },\n hChildren: svgTree.children as ElementContent[],\n } as EmbeddedHastData;\n return;\n }\n\n const message = formatKDiagramBuildError(diagnostics);\n node.lang = undefined;\n node.meta = undefined;\n node.value = message;\n node.data = {\n ...node.data,\n hName: \"pre\",\n hProperties: { className: [\"kdiagram-error\"] },\n hChildren: [\n {\n type: \"element\",\n tagName: \"code\",\n properties: {},\n children: [{ type: \"text\", value: message }],\n },\n ],\n } as EmbeddedHastData;\n }),\n );\n };\n};\n\nexport default remarkKDiagram;\nexport { remarkKDiagram };\n\nfunction mapDiagnostic(node: Code, diagnostic: Diagnostic): KDiagramRemarkDiagnostic {\n const contentStart = (node.position?.start.line ?? 1) + 1;\n const mapped = offsetKDiagramDiagnostic(diagnostic, contentStart);\n return {\n ...diagnostic,\n markdownLine: mapped.hostLine,\n markdownEndLine: mapped.hostEndLine,\n };\n}\n"],"mappings":";;;;AA6BA,MAAM,iBAAyD,SAAS,eACtE,UAAU,CAAC,GACX;CACA,OAAO,OAAO,MAAM,SAAS;EAC3B,MAAM,SAAiB,CAAC;EACxB,MAAM,MAAM,SAAS,SAAS;GAC5B,IAAI,KAAK,MAAM,YAAY,MAAM,YAAY,OAAO,KAAK,IAAI;EAC/D,CAAC;EAED,MAAM,QAAQ,IACZ,OAAO,IAAI,OAAO,SAAS;GACzB,MAAM,SAAS,MAAM,uBAAuB,KAAK,OAAO,EACtD,eAAe,QAAQ,cACzB,CAAC;GACD,MAAM,cAAc,OAAO,YAAY,KAAK,eAAe,cAAc,MAAM,UAAU,CAAC;GAC1F,KAAK,MAAM,cAAc,aAAa;IACpC,QAAQ,eAAe,UAAU;IACjC,KAAK,QAAQ,WAAW,SAAS;KAC/B,OAAO;MAAE,MAAM,WAAW;MAAc,QAAQ,WAAW,OAAO,MAAM,UAAU;KAAE;KACpF,KAAK;MAAE,MAAM,WAAW;MAAiB,QAAQ,WAAW,OAAO,IAAI,UAAU;KAAE;IACrF,CAAC,CAAC,CAAC,SAAS,WAAW;GACzB;GAEA,IAAI,OAAO,KAAK;IACd,MAAM,UAAU,SAAS,OAAO,KAAK,EAAE,UAAU,KAAK,CAAC;IACvD,KAAK,OAAO;KACV,GAAG,KAAK;KACR,OAAO;KACP,aAAa,EAAE,WAAW,CAAC,QAAQ,aAAa,WAAW,EAAE;KAC7D,WAAW,QAAQ;IACrB;IACA;GACF;GAEA,MAAM,UAAU,yBAAyB,WAAW;GACpD,KAAK,OAAO,KAAA;GACZ,KAAK,OAAO,KAAA;GACZ,KAAK,QAAQ;GACb,KAAK,OAAO;IACV,GAAG,KAAK;IACR,OAAO;IACP,aAAa,EAAE,WAAW,CAAC,gBAAgB,EAAE;IAC7C,WAAW,CACT;KACE,MAAM;KACN,SAAS;KACT,YAAY,CAAC;KACb,UAAU,CAAC;MAAE,MAAM;MAAQ,OAAO;KAAQ,CAAC;IAC7C,CACF;GACF;EACF,CAAC,CACH;CACF;AACF;AAKA,SAAS,cAAc,MAAY,YAAkD;CAEnF,MAAM,SAAS,yBAAyB,aADlB,KAAK,UAAU,MAAM,QAAQ,KAAK,CACQ;CAChE,OAAO;EACL,GAAG;EACH,cAAc,OAAO;EACrB,iBAAiB,OAAO;CAC1B;AACF"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@kekonic/diagrams-remark",
3
+ "version": "1.0.0-rc.4",
4
+ "description": "Static KDiagram diagrams for Remark, Unified, MDX, and Astro.",
5
+ "keywords": [
6
+ "astro",
7
+ "diagram",
8
+ "kdiagram",
9
+ "mdx",
10
+ "remark",
11
+ "unified"
12
+ ],
13
+ "homepage": "https://github.com/kekonic/diagrams#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/kekonic/diagrams/issues"
16
+ },
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/kekonic/diagrams.git",
21
+ "directory": "packages/diagrams-remark"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.mts",
30
+ "import": "./dist/index.mjs"
31
+ }
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "dependencies": {
37
+ "hast-util-from-html": "^2.0.3",
38
+ "unist-util-visit": "^5.0.0",
39
+ "@kekonic/diagrams": "1.0.0-rc.4",
40
+ "@kekonic/diagrams-build": "1.0.0-rc.4"
41
+ },
42
+ "devDependencies": {
43
+ "@types/hast": "^3.0.4",
44
+ "@types/mdast": "^4.0.4",
45
+ "rehype-stringify": "^10.0.1",
46
+ "remark-parse": "^11.0.0",
47
+ "remark-rehype": "^11.1.2",
48
+ "typescript": "^5",
49
+ "unified": "^11.0.5",
50
+ "vitest": "^4"
51
+ },
52
+ "peerDependencies": {
53
+ "unified": ">=11"
54
+ },
55
+ "engines": {
56
+ "node": ">=22.18.0"
57
+ },
58
+ "scripts": {
59
+ "build": "vp pack",
60
+ "test": "vp test"
61
+ }
62
+ }