comark 0.2.1 → 0.3.0

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 (64) hide show
  1. package/README.md +12 -2
  2. package/dist/internal/frontmatter.d.ts +2 -1
  3. package/dist/internal/frontmatter.js +2 -2
  4. package/dist/internal/parse/auto-close/index.js +58 -23
  5. package/dist/internal/parse/token-processor.js +18 -3
  6. package/dist/internal/stringify/attributes.d.ts +37 -1
  7. package/dist/internal/stringify/attributes.js +96 -12
  8. package/dist/internal/stringify/handlers/a.js +3 -0
  9. package/dist/internal/stringify/handlers/code.js +1 -1
  10. package/dist/internal/stringify/handlers/del.js +1 -1
  11. package/dist/internal/stringify/handlers/html.js +12 -1
  12. package/dist/internal/stringify/handlers/img.js +1 -1
  13. package/dist/internal/stringify/handlers/li.js +14 -1
  14. package/dist/internal/stringify/handlers/math.js +1 -1
  15. package/dist/internal/stringify/handlers/mdc.js +1 -1
  16. package/dist/internal/stringify/handlers/ol.js +2 -2
  17. package/dist/internal/stringify/handlers/pre.js +1 -1
  18. package/dist/internal/stringify/handlers/template.js +1 -1
  19. package/dist/internal/stringify/handlers/ul.js +2 -2
  20. package/dist/internal/stringify/indent.d.ts +2 -1
  21. package/dist/internal/stringify/indent.js +3 -2
  22. package/dist/internal/stringify/state.d.ts +3 -3
  23. package/dist/internal/stringify/state.js +71 -15
  24. package/dist/internal/yaml.d.ts +2 -1
  25. package/dist/internal/yaml.js +3 -1
  26. package/dist/parse.js +13 -2
  27. package/dist/plugins/alert.js +1 -1
  28. package/dist/plugins/binding.d.ts +20 -0
  29. package/dist/plugins/binding.js +61 -0
  30. package/dist/plugins/breaks.d.ts +2 -0
  31. package/dist/plugins/breaks.js +34 -0
  32. package/dist/plugins/footnotes.d.ts +61 -0
  33. package/dist/plugins/footnotes.js +187 -0
  34. package/dist/plugins/highlight.js +6 -4
  35. package/dist/plugins/json-render.d.ts +1 -1
  36. package/dist/plugins/json-render.js +3 -3
  37. package/dist/plugins/punctuation.d.ts +67 -0
  38. package/dist/plugins/punctuation.js +236 -0
  39. package/dist/plugins/security.js +1 -1
  40. package/dist/render.d.ts +2 -1
  41. package/dist/render.js +3 -1
  42. package/dist/types.d.ts +71 -16
  43. package/dist/utils/index.d.ts +9 -0
  44. package/dist/utils/index.js +24 -0
  45. package/dist/vite.d.ts +1 -0
  46. package/dist/vite.js +1 -0
  47. package/package.json +29 -24
  48. package/skills/comark/AGENTS.md +261 -0
  49. package/skills/comark/SKILL.md +489 -0
  50. package/skills/comark/references/markdown-syntax.md +599 -0
  51. package/skills/comark/references/parsing-ast.md +378 -0
  52. package/skills/comark/references/rendering-react.md +445 -0
  53. package/skills/comark/references/rendering-svelte.md +453 -0
  54. package/skills/comark/references/rendering-vue.md +462 -0
  55. package/skills/skills/comark/AGENTS.md +261 -0
  56. package/skills/skills/comark/SKILL.md +489 -0
  57. package/skills/skills/comark/references/markdown-syntax.md +599 -0
  58. package/skills/skills/comark/references/parsing-ast.md +378 -0
  59. package/skills/skills/comark/references/rendering-react.md +445 -0
  60. package/skills/skills/comark/references/rendering-svelte.md +453 -0
  61. package/skills/skills/comark/references/rendering-vue.md +462 -0
  62. package/skills/skills/migrate-mdc-to-comark/SKILL.md +191 -0
  63. package/dist/utils/serialized-task.d.ts +0 -1
  64. package/dist/utils/serialized-task.js +0 -1
@@ -0,0 +1,599 @@
1
+ # Markdown Syntax Guide
2
+
3
+ Complete guide for writing Comark (Components in Markdown) documents.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Standard Markdown](#standard-markdown)
8
+ - [Frontmatter](#frontmatter)
9
+ - [Comark Components](#comark-components)
10
+ - [Attributes](#attributes)
11
+ - [Code Blocks](#code-blocks)
12
+ - [Task Lists](#task-lists)
13
+ - [Tables](#tables)
14
+
15
+ ---
16
+
17
+ ## Standard Markdown
18
+
19
+ Comark supports all standard CommonMark and GitHub Flavored Markdown (GFM) features:
20
+
21
+ ### Headings
22
+
23
+ ```markdown
24
+ # Heading 1
25
+ ## Heading 2
26
+ ### Heading 3
27
+ #### Heading 4
28
+ ##### Heading 5
29
+ ###### Heading 6
30
+ ```
31
+
32
+ **Note:** All headings automatically get ID attributes generated from their content for linking (e.g., `# Hello World` becomes `<h1 id="hello-world">`).
33
+
34
+ ### Text Formatting
35
+
36
+ ```markdown
37
+ **Bold text**
38
+ *Italic text*
39
+ ***Bold and italic***
40
+ ~~Strikethrough~~
41
+ `Inline code`
42
+ ```
43
+
44
+ ### Lists
45
+
46
+ ```markdown
47
+ <!-- Unordered lists -->
48
+ - Item 1
49
+ - Item 2
50
+ - Nested item
51
+ - Another nested item
52
+
53
+ <!-- Ordered lists -->
54
+ 1. First item
55
+ 2. Second item
56
+ 1. Nested item
57
+ 2. Another nested item
58
+ ```
59
+
60
+ ### Links and Images
61
+
62
+ ```markdown
63
+ [Link text](https://example.com)
64
+ [Link with title](https://example.com "Link title")
65
+ ![Image alt text](https://example.com/image.png)
66
+ ```
67
+
68
+ ### Blockquotes
69
+
70
+ ```markdown
71
+ > This is a blockquote
72
+ > It can span multiple lines
73
+ >
74
+ > And contain other markdown elements
75
+ ```
76
+
77
+ ### Horizontal Rules
78
+
79
+ ```markdown
80
+ ---
81
+ ***
82
+ ___
83
+ ```
84
+
85
+ ### Line Breaks
86
+
87
+ ```markdown
88
+ Line with two trailing spaces
89
+ Creates a hard line break
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Frontmatter
95
+
96
+ Comark supports YAML frontmatter at the beginning of documents:
97
+
98
+ ```markdown
99
+ ---
100
+ title: My Document Title
101
+ author: John Doe
102
+ date: 2024-01-15
103
+ tags:
104
+ - markdown
105
+ - documentation
106
+ custom_field: custom value
107
+ ---
108
+
109
+ # Document Content
110
+
111
+ Your markdown content here...
112
+ ```
113
+
114
+ ### Features
115
+
116
+ - Must be at the very beginning of the document
117
+ - Enclosed by `---` delimiters
118
+ - Parsed as YAML
119
+ - Available in the `frontmatter` property of ComarkTree
120
+
121
+ ### Common Fields
122
+
123
+ - **title**: Often used for page titles or TOC labels
124
+
125
+ Note: `depth` and `searchDepth` are not automatically processed from frontmatter. They must be explicitly passed to the `toc` plugin options.
126
+
127
+ ### Example
128
+
129
+ ```typescript
130
+ import { parse } from 'comark'
131
+
132
+ const content = `---
133
+ title: My Article
134
+ depth: 3
135
+ ---
136
+
137
+ # Introduction
138
+ Content here...
139
+ `
140
+
141
+ const result = await parse(content)
142
+ console.log(result.frontmatter)
143
+ // { title: 'My Article', depth: 3 }
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Comark Components
149
+
150
+ Comark (Components in Markdown) extends standard markdown with custom component syntax.
151
+
152
+ ### Block Components
153
+
154
+ Block components use the `::component-name` syntax:
155
+
156
+ ```markdown
157
+ ::component-name{prop1="value1" prop2="value2"}
158
+ Content inside the component
159
+
160
+ Can have **markdown** and other elements
161
+ ::
162
+ ```
163
+
164
+ #### Examples
165
+
166
+ ```markdown
167
+ <!-- Alert component -->
168
+ ::alert{type="info"}
169
+ This is an important message!
170
+ ::
171
+
172
+ <!-- Card component -->
173
+ ::card{title="My Card"}
174
+ Card content with **markdown** support
175
+ ::
176
+
177
+ <!-- Empty component -->
178
+ ::divider
179
+ ::
180
+ ```
181
+
182
+ ### Inline Components
183
+
184
+ Inline components use the `:component-name` syntax:
185
+
186
+ ```markdown
187
+ <!-- Standalone inline component -->
188
+ :icon-check
189
+
190
+ <!-- Inline component with content -->
191
+ :badge[New]{color="blue"}
192
+
193
+ <!-- Inline component with properties -->
194
+ :tooltip{text="Hover text"}
195
+ ```
196
+
197
+ #### Examples
198
+
199
+ ```markdown
200
+ Check out this :icon-star component in the middle of text.
201
+
202
+ Click the :button[Submit]{type="primary"} to continue.
203
+
204
+ The status is :badge[Active]{color="green"} right now.
205
+ ```
206
+
207
+ ### Component Properties
208
+
209
+ Components support various property syntaxes:
210
+
211
+ ```markdown
212
+ ::component{prop="value"}
213
+ <!-- Standard key-value pair -->
214
+ ::
215
+
216
+ ::component{bool}
217
+ <!-- Boolean property (becomes :bool="true" in AST) -->
218
+ ::
219
+
220
+ ::component{#custom-id}
221
+ <!-- ID attribute -->
222
+ ::
223
+
224
+ ::component{.class-name}
225
+ <!-- CSS class -->
226
+ ::
227
+
228
+ ::component{obj='{"key": "value"}'}
229
+ <!-- Object/JSON value -->
230
+ ::
231
+
232
+ ::component{arr='["item1", "item2"]'}
233
+ <!-- Array/JSON value -->
234
+ ::
235
+
236
+ ::component{multiple="props" bool #id .class}
237
+ <!-- Multiple properties combined -->
238
+ ::
239
+ ```
240
+
241
+ ### Component Slots
242
+
243
+ Block components support named slots using the `#slot-name` syntax:
244
+
245
+ ```markdown
246
+ ::card
247
+ #header
248
+ ## Card Title
249
+
250
+ #content
251
+ This is the main content of the card
252
+
253
+ #footer
254
+ Footer text here
255
+
256
+ #default
257
+ Default slot
258
+ ::
259
+ ```
260
+
261
+ #### AST Output
262
+
263
+ ```json
264
+ {
265
+ "nodes": [
266
+ [
267
+ "card",
268
+ {},
269
+ [
270
+ "template",
271
+ { "name": "header" },
272
+ ["h2", {}, "Card Title"]
273
+ ],
274
+ [
275
+ "template",
276
+ { "name": "content" },
277
+ ["p", {}, "This is the main content of the card"]
278
+ ],
279
+ [
280
+ "template",
281
+ { "name": "footer" },
282
+ ["p", {}, "Footer text here"]
283
+ ],
284
+ [
285
+ "template",
286
+ { "name": "default" },
287
+ ["p", {}, "Default slot"]
288
+ ]
289
+ ]
290
+ ],
291
+ "frontmatter": {},
292
+ "meta": {}
293
+ }
294
+ ```
295
+
296
+ ### Default Slot
297
+
298
+ Content inside a component without a slot marker is the **default slot**. These two forms are equivalent in rendering but produce different ASTs:
299
+
300
+ ```markdown
301
+ ::component
302
+ hello
303
+ ::
304
+ ```
305
+
306
+ ```markdown
307
+ ::component
308
+ #default
309
+ hello
310
+ ::
311
+ ```
312
+
313
+ **Without `#default`** — content becomes direct children (auto-unwrapped):
314
+ ```json
315
+ ["component", {}, "hello"]
316
+ ```
317
+
318
+ **With `#default`** — content is wrapped in an explicit template node:
319
+ ```json
320
+ ["component", {}, ["template", { "name": "default" }, "hello"]]
321
+ ```
322
+
323
+ Both serialize back to the same Markdown (without `#default`). The Vue and React renderers treat both forms identically — direct children and `template[name="default"]` children both become the default slot. Use `#default` explicitly when mixing named and default slots in the same component.
324
+
325
+ ### Nested Components
326
+
327
+ Components can be nested within each other:
328
+
329
+ ```markdown
330
+ ::outer-component
331
+ Content in outer
332
+
333
+ :::inner-component{variant="compact"}
334
+ Content in inner
335
+ :::
336
+
337
+ More content in outer
338
+ ::
339
+ ```
340
+
341
+ ---
342
+
343
+ ## Attributes
344
+
345
+ Comark allows adding custom attributes to native markdown elements using `{...}` syntax after the element.
346
+
347
+ ### Strong/Bold Attributes
348
+
349
+ ```markdown
350
+ **bold text**{.highlight #important}
351
+ **bold text**{data-value="custom"}
352
+ **bold text**{bool}
353
+ ```
354
+
355
+ ### Italic/Emphasis Attributes
356
+
357
+ ```markdown
358
+ *italic text*{.emphasized}
359
+ _italic text_{#custom-id}
360
+ ```
361
+
362
+ ### Link Attributes
363
+
364
+ ```markdown
365
+ [Link text](url){target="_blank" rel="noopener"}
366
+ [Link text](url){.button .primary}
367
+ [External](https://example.com){target="_blank" .external-link}
368
+ ```
369
+
370
+ ### Image Attributes
371
+
372
+ ```markdown
373
+ ![Alt text](image.png){.responsive width="800" height="600"}
374
+ ![Logo](logo.svg){.logo #site-logo}
375
+ ```
376
+
377
+ ### Inline Code Attributes
378
+
379
+ ```markdown
380
+ `code snippet`{.language-js}
381
+ `variable`{data-type="string"}
382
+ ```
383
+
384
+ ### Span Attributes
385
+
386
+ ```markdown
387
+ This is [highlighted text]{.highlight .yellow} in a paragraph.
388
+ ```
389
+
390
+ ### Attribute Types
391
+
392
+ - **Boolean:** `{bool}` → `:bool="true"`
393
+ - **ID:** `{#my-id}` → `id="my-id"`
394
+ - **Class:** `{.my-class}` → `class="my-class"`
395
+ - **Key-Value:** `{key="value"}` → `key="value"`
396
+ - **JSON Objects:** `{data='{"key": "val"}'}` → `data={"key": "val"}`
397
+
398
+ ---
399
+
400
+ ## Code Blocks
401
+
402
+ Comark provides advanced code block features with metadata support.
403
+
404
+ ### Basic Code Block
405
+
406
+ ````markdown
407
+ ```javascript
408
+ function hello() {
409
+ console.log("Hello, World!")
410
+ }
411
+ ```
412
+ ````
413
+
414
+ ### Language with Syntax Highlighting
415
+
416
+ ````markdown
417
+ ```typescript
418
+ interface User {
419
+ name: string
420
+ age: number
421
+ }
422
+ ```
423
+ ````
424
+
425
+ ### Filename Metadata
426
+
427
+ ````markdown
428
+ ```javascript [server.js]
429
+ const express = require('express')
430
+ const app = express()
431
+ ```
432
+ ````
433
+
434
+ **Note:** Filename is enclosed in `[...]` brackets.
435
+
436
+ ### Line Highlighting
437
+
438
+ ````markdown
439
+ ```javascript {1-3,5}
440
+ function example() {
441
+ const a = 1 // Lines 1-3 highlighted
442
+ const b = 2
443
+ const c = 3
444
+ return a + b + c // Line 5 highlighted
445
+ }
446
+ ```
447
+ ````
448
+
449
+ #### Highlighting Syntax
450
+
451
+ - Single line: `{3}`
452
+ - Range: `{1-5}`
453
+ - Multiple: `{1,3,5}`
454
+ - Combined: `{1-3,7,10-12}`
455
+
456
+ ### Combined Metadata
457
+
458
+ ````markdown
459
+ ```javascript {1-3} [utils.ts] meta=value
460
+ function hello() {
461
+ console.log("Hello")
462
+ }
463
+ ```
464
+ ````
465
+
466
+ **Metadata Order:** Any order is supported:
467
+ - `language {highlights} [filename] meta`
468
+ - `language [filename] {highlights} meta`
469
+ - etc.
470
+
471
+ ### Special Characters in Filename
472
+
473
+ ````markdown
474
+ ```typescript [@[...slug\].ts]
475
+ // Brackets and special chars are supported
476
+ // Backslash escapes special characters
477
+ ```
478
+ ````
479
+
480
+ ### No Language Specified
481
+
482
+ ````markdown
483
+ ```
484
+ Plain text code block
485
+ No syntax highlighting
486
+ ```
487
+ ````
488
+
489
+ ### AST Structure
490
+
491
+ ```json
492
+ {
493
+ "nodes": [
494
+ [
495
+ "pre",
496
+ {
497
+ "language": "javascript",
498
+ "filename": "server.js",
499
+ "highlights": [1, 2, 3],
500
+ "meta": "meta=value"
501
+ },
502
+ [
503
+ "code",
504
+ { "class": "language-javascript" },
505
+ "code content here"
506
+ ]
507
+ ]
508
+ ],
509
+ "frontmatter": {},
510
+ "meta": {}
511
+ }
512
+ ```
513
+
514
+ ---
515
+
516
+ ## Task Lists
517
+
518
+ Comark supports GitHub Flavored Markdown task lists:
519
+
520
+ ```markdown
521
+ - [x] Completed task
522
+ - [ ] Pending task
523
+ - [x] Another completed task
524
+ - [ ] Nested pending task
525
+ - [x] Nested completed task
526
+ ```
527
+
528
+ ### Features
529
+
530
+ - `[x]` or `[X]` for completed tasks
531
+ - `[ ]` for pending tasks
532
+ - Works in both ordered and unordered lists
533
+ - Supports nesting
534
+
535
+ ### HTML Output
536
+
537
+ ```html
538
+ <ul class="contains-task-list">
539
+ <li class="task-list-item">
540
+ <input type="checkbox" disabled checked class="task-list-item-checkbox">
541
+ Completed task
542
+ </li>
543
+ <li class="task-list-item">
544
+ <input type="checkbox" disabled class="task-list-item-checkbox">
545
+ Pending task
546
+ </li>
547
+ </ul>
548
+ ```
549
+
550
+ ---
551
+
552
+ ## Tables
553
+
554
+ Comark supports GitHub Flavored Markdown tables:
555
+
556
+ ```markdown
557
+ | Header 1 | Header 2 | Header 3 |
558
+ | -------- | -------- | -------- |
559
+ | Cell 1 | Cell 2 | Cell 3 |
560
+ | Cell 4 | Cell 5 | Cell 6 |
561
+ ```
562
+
563
+ ### Aligned Tables
564
+
565
+ ```markdown
566
+ | Left Aligned | Center Aligned | Right Aligned |
567
+ | :----------- | :------------: | ------------: |
568
+ | Left | Center | Right |
569
+ | Text | Text | Text |
570
+ ```
571
+
572
+ #### Alignment Syntax
573
+
574
+ - Left: `:---`
575
+ - Center: `:---:`
576
+ - Right: `---:`
577
+
578
+ ### Inline Markdown in Tables
579
+
580
+ ```markdown
581
+ | Feature | Status | Link |
582
+ | ------------ | --------------- | ----------------------- |
583
+ | **Bold** | *Italic* | [Link](https://example) |
584
+ | `Code` | ~~Strike~~ | ![Image](img.png) |
585
+ ```
586
+
587
+ ### Varying Column Widths
588
+
589
+ ```markdown
590
+ | Short | Medium Column | Very Long Column Name Here |
591
+ | ----- | ------------- | -------------------------- |
592
+ | A | B | C |
593
+ ```
594
+
595
+ **Note:** Column width is determined by the longest content in each column.
596
+
597
+ ---
598
+
599
+ [← Back to Main Skills Guide](../../SKILLS.md)