comark 0.3.1 → 0.4.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 (93) hide show
  1. package/dist/internal/frontmatter.d.ts +1 -0
  2. package/dist/internal/frontmatter.js +4 -2
  3. package/dist/internal/parse/auto-close/index.js +69 -31
  4. package/dist/internal/parse/auto-close/table.js +12 -9
  5. package/dist/internal/parse/auto-unwrap.js +6 -10
  6. package/dist/internal/parse/html/html_block_rule.js +10 -16
  7. package/dist/internal/parse/html/html_inline_rule.js +3 -7
  8. package/dist/internal/parse/html/html_re.js +1 -1
  9. package/dist/internal/parse/html/index.d.ts +1 -0
  10. package/dist/internal/parse/html/index.js +15 -3
  11. package/dist/internal/parse/syntax/block-params.d.ts +9 -0
  12. package/dist/internal/parse/syntax/block-params.js +48 -0
  13. package/dist/internal/parse/syntax/brackets.d.ts +8 -0
  14. package/dist/internal/parse/syntax/brackets.js +20 -0
  15. package/dist/internal/parse/syntax/props.d.ts +5 -0
  16. package/dist/internal/parse/syntax/props.js +119 -0
  17. package/dist/internal/parse/token-processor.js +89 -50
  18. package/dist/internal/props-validation.js +4 -9
  19. package/dist/internal/stringify/attributes.d.ts +7 -0
  20. package/dist/internal/stringify/attributes.js +56 -1
  21. package/dist/internal/stringify/handlers/a.js +1 -3
  22. package/dist/internal/stringify/handlers/blockquote.js +19 -4
  23. package/dist/internal/stringify/handlers/code.js +1 -3
  24. package/dist/internal/stringify/handlers/emphesis.js +1 -3
  25. package/dist/internal/stringify/handlers/heading.js +6 -1
  26. package/dist/internal/stringify/handlers/html.js +34 -18
  27. package/dist/internal/stringify/handlers/img.js +1 -3
  28. package/dist/internal/stringify/handlers/li.js +18 -9
  29. package/dist/internal/stringify/handlers/mdc.js +3 -4
  30. package/dist/internal/stringify/handlers/ol.js +12 -2
  31. package/dist/internal/stringify/handlers/p.d.ts +1 -1
  32. package/dist/internal/stringify/handlers/p.js +8 -1
  33. package/dist/internal/stringify/handlers/pre.js +20 -14
  34. package/dist/internal/stringify/handlers/strong.js +1 -3
  35. package/dist/internal/stringify/handlers/table.js +14 -5
  36. package/dist/internal/stringify/handlers/template.js +5 -2
  37. package/dist/internal/stringify/handlers/ul.js +12 -2
  38. package/dist/internal/stringify/state.js +1 -1
  39. package/dist/internal/yaml.js +1 -1
  40. package/dist/parse.d.ts +4 -4
  41. package/dist/parse.js +20 -10
  42. package/dist/plugins/alert.d.ts +1 -1
  43. package/dist/plugins/alert.js +1 -1
  44. package/dist/plugins/binding.d.ts +1 -1
  45. package/dist/plugins/binding.js +1 -3
  46. package/dist/plugins/breaks.d.ts +1 -1
  47. package/dist/plugins/breaks.js +1 -1
  48. package/dist/plugins/emoji.d.ts +1 -1
  49. package/dist/plugins/emoji.js +8 -8
  50. package/dist/plugins/footnotes.d.ts +1 -1
  51. package/dist/plugins/footnotes.js +19 -13
  52. package/dist/plugins/headings.d.ts +19 -8
  53. package/dist/plugins/headings.js +27 -19
  54. package/dist/plugins/highlight.d.ts +2 -12
  55. package/dist/plugins/highlight.js +201 -103
  56. package/dist/plugins/json-render.d.ts +1 -1
  57. package/dist/plugins/json-render.js +5 -9
  58. package/dist/plugins/math.d.ts +1 -1
  59. package/dist/plugins/math.js +4 -6
  60. package/dist/plugins/mermaid.d.ts +1 -1
  61. package/dist/plugins/mermaid.js +6 -20
  62. package/dist/plugins/punctuation.d.ts +1 -1
  63. package/dist/plugins/punctuation.js +5 -6
  64. package/dist/plugins/security.d.ts +1 -1
  65. package/dist/plugins/security.js +2 -2
  66. package/dist/plugins/summary.d.ts +4 -1
  67. package/dist/plugins/syntax.d.ts +49 -0
  68. package/dist/plugins/syntax.js +558 -0
  69. package/dist/plugins/task-list.d.ts +2 -2
  70. package/dist/plugins/task-list.js +11 -8
  71. package/dist/plugins/toc.d.ts +3 -1
  72. package/dist/plugins/toc.js +1 -1
  73. package/dist/types.d.ts +57 -12
  74. package/dist/utils/comark.tmLanguage.d.ts +335 -0
  75. package/dist/utils/comark.tmLanguage.js +597 -0
  76. package/dist/utils/helpers.d.ts +16 -4
  77. package/dist/utils/helpers.js +16 -6
  78. package/dist/utils/index.d.ts +5 -0
  79. package/dist/utils/index.js +25 -3
  80. package/package.json +40 -40
  81. package/skills/comark/references/rendering-svelte.md +51 -7
  82. package/dist/internal/stringify/indent.d.ts +0 -5
  83. package/dist/internal/stringify/indent.js +0 -9
  84. package/dist/vite.d.ts +0 -1
  85. package/dist/vite.js +0 -1
  86. package/skills/skills/comark/AGENTS.md +0 -261
  87. package/skills/skills/comark/SKILL.md +0 -489
  88. package/skills/skills/comark/references/markdown-syntax.md +0 -599
  89. package/skills/skills/comark/references/parsing-ast.md +0 -378
  90. package/skills/skills/comark/references/rendering-react.md +0 -445
  91. package/skills/skills/comark/references/rendering-svelte.md +0 -453
  92. package/skills/skills/comark/references/rendering-vue.md +0 -462
  93. /package/skills/{skills/migrate-mdc-to-comark → migrate-mdc-to-comark}/SKILL.md +0 -0
package/dist/types.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { DumpOptions } from 'js-yaml';
2
2
  import type MarkdownExit from 'markdown-exit';
3
3
  import type MarkdownIt from 'markdown-it';
4
+ /**
5
+ * The `[keyof T] extends [never]` form (rather than `keyof T extends never`)
6
+ * is the standard trick to prevent TS from distributing the check over a
7
+ * union — we want to test "is T's keyset empty?" as one yes/no question.
8
+ */
9
+ type Writable<T> = [keyof T] extends [never] ? Record<string, any> : T;
4
10
  /**
5
11
  * The Comark text
6
12
  * @param string - The text content
@@ -43,11 +49,14 @@ export type ComarkNode = ComarkElement | ComarkText | ComarkComment;
43
49
  * @param nodes - The nodes of the tree
44
50
  * @param frontmatter - The frontmatter data which is the data at the top of the file
45
51
  * @param meta - The meta data of tree, it can be used to store additional data for the tree
52
+ *
53
+ * The `TMeta` and `TFrontmatter` type parameters allow `parse` / `createParse`
54
+ * to surface plugin-contributed keys with narrow types (see `MergePluginMeta`).
46
55
  */
47
- export interface ComarkTree {
56
+ export interface ComarkTree<TMeta = Record<string, any>, TFrontmatter = Record<string, any>> {
48
57
  nodes: ComarkNode[];
49
- frontmatter: Record<string, any>;
50
- meta: Record<string, any>;
58
+ frontmatter: TFrontmatter;
59
+ meta: TMeta;
51
60
  }
52
61
  export interface ContextBase {
53
62
  /**
@@ -228,31 +237,66 @@ export interface NodeRenderData {
228
237
  }
229
238
  export type MarkdownExitPlugin = (md: MarkdownExit) => void;
230
239
  export type MarkdownItPlugin = (md: MarkdownIt) => void;
240
+ export type MarkdownItPluginWithOptions<T> = (md: MarkdownIt, options: T) => void;
231
241
  export type ComarkParsePreState = {
232
242
  markdown: string;
233
243
  options: ParseOptions;
234
244
  [key: string]: any;
235
245
  };
236
- export type ComarkParsePostState = {
246
+ export type ComarkParsePostState<TMeta = Record<string, any>, TFrontmatter = Record<string, any>> = {
237
247
  markdown: string;
238
- tree: ComarkTree;
248
+ tree: ComarkTree<TMeta, TFrontmatter>;
239
249
  options: ParseOptions;
240
250
  tokens: unknown[];
241
251
  [key: string]: any;
242
252
  };
243
- export type ComarkPlugin = {
253
+ /**
254
+ * A Comark plugin.
255
+ *
256
+ * `TMeta` / `TFrontmatter` are phantom type parameters that record what this
257
+ * plugin contributes to `tree.meta` / `tree.frontmatter`. They are surfaced
258
+ * only via the optional `__meta` / `__frontmatter` markers — implementations
259
+ * never set these at runtime; they exist purely so the contribution survives
260
+ * `ReturnType<typeof factory>` inference and can be merged in `createParse`.
261
+ */
262
+ export type ComarkPlugin<TMeta = {}, TFrontmatter = {}> = {
244
263
  name: string;
245
264
  markdownItPlugins?: MarkdownItPlugin[];
246
265
  pre?: (state: ComarkParsePreState) => Promise<void> | void;
247
- post?: (state: ComarkParsePostState) => Promise<void> | void;
266
+ post?: (state: ComarkParsePostState<Writable<TMeta>, Writable<TFrontmatter>>) => Promise<void> | void;
267
+ /** Phantom — used for type inference only. Never set at runtime. */
268
+ __meta?: TMeta;
269
+ /** Phantom — used for type inference only. Never set at runtime. */
270
+ __frontmatter?: TFrontmatter;
248
271
  };
249
- export type ComarkPluginFactory<Options> = (opts?: Options) => ComarkPlugin;
250
- export type ComponentManifest = (name: string) => Promise<unknown> | undefined | null;
272
+ export type ComarkPluginFactory<Options, TMeta = {}, TFrontmatter = {}> = (opts?: Options) => ComarkPlugin<TMeta, TFrontmatter>;
273
+ type PluginMetaOf<P> = P extends ComarkPlugin<infer M, any> ? M : {};
274
+ type PluginFrontmatterOf<P> = P extends ComarkPlugin<any, infer F> ? F : {};
275
+ /**
276
+ * Walk a tuple of plugins and intersect their meta contributions.
277
+ * Returns `{}` when the tuple is empty or when nothing was contributed.
278
+ */
279
+ export type MergePluginMeta<TPlugins extends readonly unknown[]> = TPlugins extends readonly [infer Head, ...infer Rest] ? PluginMetaOf<Head> & MergePluginMeta<Rest extends readonly unknown[] ? Rest : []> : {};
280
+ /**
281
+ * Walk a tuple of plugins and intersect their frontmatter contributions.
282
+ */
283
+ export type MergePluginFrontmatter<TPlugins extends readonly unknown[]> = TPlugins extends readonly [
284
+ infer Head,
285
+ ...infer Rest
286
+ ] ? PluginFrontmatterOf<Head> & MergePluginFrontmatter<Rest extends readonly unknown[] ? Rest : []> : {};
287
+ /**
288
+ * When no plugin contributed meta keys, fall back to the permissive
289
+ * `Record<string, any>` (backwards-compatible). Otherwise, preserve narrow
290
+ * keys and type unknown accesses as `unknown` (safer than `any`).
291
+ */
292
+ export type ResolvedMeta<T> = [keyof T] extends [never] ? Record<string, any> : T & Record<string, unknown>;
293
+ export type ResolvedFrontmatter<T> = [keyof T] extends [never] ? Record<string, any> : T & Record<string, unknown>;
294
+ export type ComponentManifest = (name: string) => unknown | Promise<unknown> | undefined | null;
251
295
  export interface ComarkContextProvider {
252
296
  components: Record<string, any>;
253
297
  componentManifest: ComponentManifest;
254
298
  }
255
- export interface ParseOptions {
299
+ export interface ParseOptions<TPlugins extends readonly ComarkPlugin<any, any>[] = readonly ComarkPlugin<any, any>[]> {
256
300
  /**
257
301
  * Whether to automatically unwrap single paragraphs in container components.
258
302
  * When enabled, if a container component (alert, card, callout, note, warning, tip, info)
@@ -299,7 +343,7 @@ export interface ParseOptions {
299
343
  * Additional plugins to use
300
344
  * @default []
301
345
  */
302
- plugins?: ComarkPlugin[];
346
+ plugins?: TPlugins;
303
347
  }
304
348
  /**
305
349
  * Type signature for the options object passed to the Comark parser function returned by createParse().
@@ -311,4 +355,5 @@ export type ComarkParseFnOptions = {
311
355
  * Type signature for the async Comark parser function returned by createParse().
312
356
  * Accepts a markdown string and optional parsing options, and returns a Promise of ComarkTree.
313
357
  */
314
- export type ComarkParseFn = (markdown: string, opts?: ComarkParseFnOptions) => Promise<ComarkTree>;
358
+ export type ComarkParseFn<TMeta = Record<string, any>, TFrontmatter = Record<string, any>> = (markdown: string, opts?: ComarkParseFnOptions) => Promise<ComarkTree<TMeta, TFrontmatter>>;
359
+ export {};
@@ -0,0 +1,335 @@
1
+ declare const _default: ({
2
+ $schema: string;
3
+ name: string;
4
+ aliases: string[];
5
+ displayName: string;
6
+ injectionSelector: string;
7
+ scopeName: string;
8
+ patterns: {
9
+ include: string;
10
+ }[];
11
+ repository: {
12
+ block: {
13
+ patterns: {
14
+ include: string;
15
+ }[];
16
+ };
17
+ inline: {
18
+ patterns: {
19
+ include: string;
20
+ }[];
21
+ };
22
+ binding: {
23
+ match: string;
24
+ name: string;
25
+ captures: {
26
+ '1': {
27
+ name: string;
28
+ };
29
+ '2': {
30
+ name: string;
31
+ };
32
+ '3': {
33
+ name: string;
34
+ };
35
+ '4': {
36
+ name: string;
37
+ };
38
+ '5': {
39
+ name: string;
40
+ };
41
+ };
42
+ };
43
+ span: {
44
+ match: string;
45
+ name: string;
46
+ captures: {
47
+ '1': {
48
+ name: string;
49
+ };
50
+ '2': {
51
+ name: string;
52
+ };
53
+ '3': {
54
+ name: string;
55
+ };
56
+ '4': {
57
+ patterns: {
58
+ include: string;
59
+ }[];
60
+ };
61
+ };
62
+ };
63
+ attributes: {
64
+ match: string;
65
+ name: string;
66
+ captures: {
67
+ '1': {
68
+ name: string;
69
+ };
70
+ '3': {
71
+ patterns: {
72
+ include: string;
73
+ }[];
74
+ };
75
+ '4': {
76
+ name: string;
77
+ };
78
+ };
79
+ };
80
+ component_inline: {
81
+ match: string;
82
+ name: string;
83
+ captures: {
84
+ '2': {
85
+ name: string;
86
+ };
87
+ '3': {
88
+ name: string;
89
+ };
90
+ '5': {
91
+ patterns: {
92
+ include: string;
93
+ }[];
94
+ };
95
+ '6': {
96
+ patterns: {
97
+ include: string;
98
+ }[];
99
+ };
100
+ '7': {
101
+ patterns: {
102
+ include: string;
103
+ }[];
104
+ };
105
+ '8': {
106
+ patterns: {
107
+ include: string;
108
+ }[];
109
+ };
110
+ };
111
+ };
112
+ component_block: {
113
+ begin: string;
114
+ name: string;
115
+ end: string;
116
+ beginCaptures: {
117
+ '3': {
118
+ name: string;
119
+ };
120
+ '4': {
121
+ name: string;
122
+ };
123
+ '5': {
124
+ patterns: {
125
+ include: string;
126
+ }[];
127
+ };
128
+ };
129
+ endCaptures: {
130
+ '3': {
131
+ name: string;
132
+ };
133
+ };
134
+ patterns: ({
135
+ match: string;
136
+ captures: {
137
+ '2': {
138
+ name: string;
139
+ };
140
+ '3'?: undefined;
141
+ };
142
+ begin?: undefined;
143
+ end?: undefined;
144
+ patterns?: undefined;
145
+ include?: undefined;
146
+ } | {
147
+ begin: string;
148
+ end: string;
149
+ patterns: {
150
+ include: string;
151
+ }[];
152
+ match?: undefined;
153
+ captures?: undefined;
154
+ include?: undefined;
155
+ } | {
156
+ match: string;
157
+ captures: {
158
+ '2': {
159
+ name: string;
160
+ };
161
+ '3': {
162
+ name: string;
163
+ };
164
+ };
165
+ begin?: undefined;
166
+ end?: undefined;
167
+ patterns?: undefined;
168
+ include?: undefined;
169
+ } | {
170
+ include: string;
171
+ match?: undefined;
172
+ captures?: undefined;
173
+ begin?: undefined;
174
+ end?: undefined;
175
+ patterns?: undefined;
176
+ })[];
177
+ };
178
+ attribute: {
179
+ patterns: {
180
+ match: string;
181
+ captures: {
182
+ '2': {
183
+ name: string;
184
+ };
185
+ '3': {
186
+ patterns: {
187
+ include: string;
188
+ }[];
189
+ };
190
+ };
191
+ }[];
192
+ };
193
+ 'attribute-interior': {
194
+ patterns: {
195
+ begin: string;
196
+ beginCaptures: {
197
+ '0': {
198
+ name: string;
199
+ };
200
+ };
201
+ end: string;
202
+ patterns: ({
203
+ match: string;
204
+ name: string;
205
+ begin?: undefined;
206
+ beginCaptures?: undefined;
207
+ end?: undefined;
208
+ endCaptures?: undefined;
209
+ patterns?: undefined;
210
+ } | {
211
+ begin: string;
212
+ beginCaptures: {
213
+ '0': {
214
+ name: string;
215
+ };
216
+ };
217
+ end: string;
218
+ endCaptures: {
219
+ '0': {
220
+ name: string;
221
+ };
222
+ };
223
+ name: string;
224
+ patterns: {
225
+ include: string;
226
+ }[];
227
+ match?: undefined;
228
+ })[];
229
+ }[];
230
+ };
231
+ entities: {
232
+ patterns: ({
233
+ captures: {
234
+ '1': {
235
+ name: string;
236
+ };
237
+ '912': {
238
+ name: string;
239
+ };
240
+ '3'?: undefined;
241
+ };
242
+ match: string;
243
+ name: string;
244
+ } | {
245
+ captures: {
246
+ '1': {
247
+ name: string;
248
+ };
249
+ '3': {
250
+ name: string;
251
+ };
252
+ '912'?: undefined;
253
+ };
254
+ match: string;
255
+ name: string;
256
+ } | {
257
+ match: string;
258
+ name: string;
259
+ captures?: undefined;
260
+ })[];
261
+ };
262
+ heading: {
263
+ match: string;
264
+ captures: {
265
+ '1': {
266
+ patterns: {
267
+ match: string;
268
+ name: string;
269
+ captures: {
270
+ '1': {
271
+ name: string;
272
+ };
273
+ '2': {
274
+ name: string;
275
+ patterns: {
276
+ include: string;
277
+ }[];
278
+ };
279
+ '3': {
280
+ name: string;
281
+ };
282
+ };
283
+ }[];
284
+ };
285
+ };
286
+ name: string;
287
+ patterns: {
288
+ include: string;
289
+ }[];
290
+ };
291
+ 'heading-setext': {
292
+ patterns: {
293
+ match: string;
294
+ name: string;
295
+ }[];
296
+ };
297
+ lists: {
298
+ patterns: {
299
+ begin: string;
300
+ beginCaptures: {
301
+ '3': {
302
+ name: string;
303
+ };
304
+ };
305
+ name: string;
306
+ patterns: {
307
+ include: string;
308
+ }[];
309
+ while: string;
310
+ }[];
311
+ };
312
+ paragraph: {
313
+ begin: string;
314
+ name: string;
315
+ patterns: {
316
+ include: string;
317
+ }[];
318
+ while: string;
319
+ };
320
+ blockquote: {
321
+ begin: string;
322
+ captures: {
323
+ '2': {
324
+ name: string;
325
+ };
326
+ };
327
+ name: string;
328
+ patterns: {
329
+ include: string;
330
+ }[];
331
+ while: string;
332
+ };
333
+ };
334
+ } | import("shiki").LanguageRegistration)[];
335
+ export default _default;