comark 0.3.2 → 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 (57) hide show
  1. package/dist/internal/parse/auto-close/index.js +44 -18
  2. package/dist/internal/parse/auto-unwrap.js +5 -1
  3. package/dist/internal/parse/html/html_block_rule.js +9 -15
  4. package/dist/internal/parse/html/index.d.ts +1 -0
  5. package/dist/internal/parse/html/index.js +1 -1
  6. package/dist/internal/parse/token-processor.js +70 -32
  7. package/dist/internal/stringify/attributes.d.ts +7 -0
  8. package/dist/internal/stringify/attributes.js +52 -0
  9. package/dist/internal/stringify/handlers/blockquote.js +17 -0
  10. package/dist/internal/stringify/handlers/heading.js +6 -1
  11. package/dist/internal/stringify/handlers/html.js +8 -2
  12. package/dist/internal/stringify/handlers/li.js +4 -1
  13. package/dist/internal/stringify/handlers/mdc.js +1 -1
  14. package/dist/internal/stringify/handlers/ol.js +11 -1
  15. package/dist/internal/stringify/handlers/p.js +4 -0
  16. package/dist/internal/stringify/handlers/pre.js +11 -2
  17. package/dist/internal/stringify/handlers/table.js +7 -0
  18. package/dist/internal/stringify/handlers/template.js +4 -1
  19. package/dist/internal/stringify/handlers/ul.js +11 -1
  20. package/dist/parse.d.ts +4 -4
  21. package/dist/parse.js +6 -2
  22. package/dist/plugins/alert.d.ts +1 -1
  23. package/dist/plugins/binding.d.ts +1 -1
  24. package/dist/plugins/breaks.d.ts +1 -1
  25. package/dist/plugins/emoji.d.ts +1 -1
  26. package/dist/plugins/footnotes.d.ts +1 -1
  27. package/dist/plugins/headings.d.ts +19 -8
  28. package/dist/plugins/headings.js +25 -15
  29. package/dist/plugins/highlight.d.ts +1 -1
  30. package/dist/plugins/highlight.js +4 -1
  31. package/dist/plugins/json-render.d.ts +1 -1
  32. package/dist/plugins/math.d.ts +1 -1
  33. package/dist/plugins/mermaid.d.ts +1 -1
  34. package/dist/plugins/punctuation.d.ts +1 -1
  35. package/dist/plugins/security.d.ts +1 -1
  36. package/dist/plugins/summary.d.ts +4 -1
  37. package/dist/plugins/syntax.d.ts +1 -1
  38. package/dist/plugins/syntax.js +70 -34
  39. package/dist/plugins/task-list.d.ts +1 -1
  40. package/dist/plugins/toc.d.ts +3 -1
  41. package/dist/types.d.ts +56 -12
  42. package/dist/utils/helpers.d.ts +16 -4
  43. package/dist/utils/helpers.js +15 -3
  44. package/package.json +3 -2
  45. package/skills/comark/references/rendering-svelte.md +51 -7
  46. package/dist/devtools/index.d.ts +0 -1
  47. package/dist/devtools/index.js +0 -1
  48. package/dist/devtools/register.d.ts +0 -1
  49. package/dist/devtools/register.js +0 -1
  50. package/dist/devtools/registry.d.ts +0 -1
  51. package/dist/devtools/registry.js +0 -1
  52. package/dist/devtools/vite.d.ts +0 -1
  53. package/dist/devtools/vite.js +0 -1
  54. package/dist/internal/stringify/indent.d.ts +0 -1
  55. package/dist/internal/stringify/indent.js +0 -1
  56. package/dist/vite.d.ts +0 -1
  57. package/dist/vite.js +0 -1
@@ -11,9 +11,21 @@ export function createSerializedTask(fn) {
11
11
  }
12
12
  // #region define plugin
13
13
  /**
14
- * Define a Comark plugin
15
- * @param fn - The plugin factory function
16
- * @returns The defined plugin
14
+ * Define a Comark plugin.
15
+ *
16
+ * `TMeta` and `TFrontmatter` declare what the plugin contributes to
17
+ * `tree.meta` / `tree.frontmatter`. They are inferred from the factory's
18
+ * return type when set via the `__meta` / `__frontmatter` phantom markers,
19
+ * or can be passed explicitly. Plugins that don't contribute typed keys can
20
+ * omit them entirely.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * defineComarkPlugin<Options, { toc: Toc }>((opts) => ({
25
+ * name: 'toc',
26
+ * post(state) { state.tree.meta.toc = ... },
27
+ * }))
28
+ * ```
17
29
  */
18
30
  export function defineComarkPlugin(fn) {
19
31
  return fn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comark",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Components in Markdown (Comark) parser with streaming support for Vue, React, Svelte and HTML",
5
5
  "keywords": [
6
6
  "markdown",
@@ -25,6 +25,7 @@
25
25
  "skills"
26
26
  ],
27
27
  "type": "module",
28
+ "sideEffects": false,
28
29
  "main": "./dist/index.js",
29
30
  "module": "./dist/index.js",
30
31
  "types": "./dist/index.d.ts",
@@ -52,7 +53,7 @@
52
53
  "github-slugger": "^2.0.0",
53
54
  "hast-util-to-string": "^3.0.1",
54
55
  "minimark": "0.2.0",
55
- "tsx": "^4.21.0",
56
+ "tsx": "^4.22.4",
56
57
  "twoslash": "^0.3.6",
57
58
  "vitest": "^4.1.4"
58
59
  },
@@ -48,9 +48,9 @@ Map custom Svelte components to Comark elements:
48
48
  ```svelte
49
49
  <script lang="ts">
50
50
  import { Comark } from '@comark/svelte'
51
- import CustomHeading from './CustomHeading.svelte'
52
- import CustomAlert from './CustomAlert.svelte'
53
- import CustomCard from './CustomCard.svelte'
51
+ import CustomHeading from './components/comark/CustomHeading.svelte'
52
+ import CustomAlert from './components/comark/CustomAlert.svelte'
53
+ import CustomCard from './components/comark/CustomCard.svelte'
54
54
 
55
55
  const customComponents = {
56
56
  h1: CustomHeading,
@@ -127,9 +127,9 @@ Load components dynamically using `componentsManifest`:
127
127
  import { Comark } from '@comark/svelte'
128
128
 
129
129
  const componentMap: Record<string, () => Promise<any>> = {
130
- 'alert': () => import('./Alert.svelte'),
131
- 'card': () => import('./Card.svelte'),
132
- 'button': () => import('./Button.svelte'),
130
+ 'alert': () => import('./components/comark/Alert.svelte'),
131
+ 'card': () => import('./components/comark/Card.svelte'),
132
+ 'button': () => import('./components/comark/Button.svelte'),
133
133
  }
134
134
 
135
135
  async function loadComponent(name: string) {
@@ -144,6 +144,50 @@ Load components dynamically using `componentsManifest`:
144
144
  <Comark markdown={content} componentsManifest={loadComponent} />
145
145
  ```
146
146
 
147
+ In SvelteKit projects, keep components rendered from Markdown in a dedicated folder such as `$lib/components/comark/`. This keeps Comark-rendered components separate from normal app UI components and makes `componentsManifest` globs easier to audit.
148
+
149
+ For SvelteKit SSR with non-eager lazy components, use `ComarkAsync` and a manifest that returns dynamic imports. An explicit map is the easiest option to audit:
150
+
151
+ ```svelte
152
+ <script lang="ts">
153
+ import { ComarkAsync } from '@comark/svelte/async'
154
+
155
+ const componentMap: Record<string, () => Promise<any>> = {
156
+ 'alert': () => import('$lib/components/comark/Alert.svelte'),
157
+ 'lazy-card': () => import('$lib/components/comark/LazyCard.svelte'),
158
+ }
159
+
160
+ const componentsManifest = (name: string) => componentMap[name]?.()
161
+ </script>
162
+
163
+ <svelte:boundary>
164
+ <ComarkAsync markdown={content} {componentsManifest} />
165
+ </svelte:boundary>
166
+ ```
167
+
168
+ Use `import.meta.glob` when you want the manifest to cover every Svelte component in a folder:
169
+
170
+ ```svelte
171
+ <script lang="ts">
172
+ import { ComarkAsync } from '@comark/svelte/async'
173
+ import { pascalCase } from '@comark/svelte/utils'
174
+
175
+ const modules = import.meta.glob('../lib/components/comark/*.svelte')
176
+
177
+ const componentsManifest = (name: string) => {
178
+ return modules[`../lib/components/comark/${pascalCase(name)}.svelte`]?.()
179
+ }
180
+ </script>
181
+
182
+ <svelte:boundary>
183
+ <ComarkAsync markdown={content} {componentsManifest} />
184
+ </svelte:boundary>
185
+ ```
186
+
187
+ Omit the boundary `pending` snippet when you want SvelteKit SSR to wait and include the resolved lazy components in the initial HTML.
188
+
189
+ Use eager/static components with `ComarkRenderer` when you need stable SSR without Svelte's experimental async support.
190
+
147
191
  ---
148
192
 
149
193
  ## Slots Support
@@ -319,7 +363,7 @@ Override native HTML elements using the `Prose` prefix:
319
363
 
320
364
  ## Experimental Async
321
365
 
322
- The `ComarkAsync` component uses Svelte's experimental `await` in `$derived` for a declarative approach. Requires `experimental.async` in your Svelte config:
366
+ The `ComarkAsync` component uses Svelte's experimental `await` in `$derived` for a declarative approach. It can also await async `componentsManifest` entries during SSR, so lazy dynamic imports render into SvelteKit server HTML. Requires `experimental.async` in your Svelte config:
323
367
 
324
368
  ```js
325
369
  // svelte.config.js
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/index'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/index.ts'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/register'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/register.ts'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/registry'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/registry.ts'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/vite'
@@ -1 +0,0 @@
1
- export * from '../../src/devtools/vite.ts'
@@ -1 +0,0 @@
1
- export * from '../../../src/internal/stringify/indent'
@@ -1 +0,0 @@
1
- export * from '../../../src/internal/stringify/indent.ts'
package/dist/vite.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '../src/vite'
package/dist/vite.js DELETED
@@ -1 +0,0 @@
1
- export * from '../src/vite.ts'