markstream-vue 0.0.7-beta.3 → 0.0.7-beta.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/README.md CHANGED
@@ -100,7 +100,7 @@ createApp({
100
100
  }).mount('#app')
101
101
  ```
102
102
 
103
- Import `markstream-vue/index.css` after your reset (e.g., Tailwind `@layer components`) so renderer styles win over utility classes. Install optional peers such as `stream-monaco`, `shiki`, `mermaid`, and `katex` only when you need Monaco code blocks, Shiki highlighting, diagrams, or math.
103
+ Import `markstream-vue/index.css` after your reset (e.g., Tailwind `@layer components`) so renderer styles win over utility classes. Install optional peers such as `stream-monaco`, `shiki`, `stream-markdown`, `mermaid`, and `katex` only when you need Monaco code blocks, Shiki highlighting, diagrams, or math.
104
104
 
105
105
  Renderer CSS is scoped under an internal `.markstream-vue` container to minimize global style conflicts. If you render exported node components outside of `MarkdownRender`, wrap them in an element with class `markstream-vue`.
106
106
 
@@ -111,6 +111,7 @@ Enable heavy peers only when needed:
111
111
  ```ts
112
112
  import { enableKatex, enableMermaid } from 'markstream-vue'
113
113
  import 'markstream-vue/index.css'
114
+ import 'katex/dist/katex.min.css'
114
115
 
115
116
  // after you install `mermaid` / `katex` peers
116
117
  enableMermaid()
@@ -280,32 +281,30 @@ Pick one mode per surface: virtualization for best scrollback and steady memory
280
281
  - `content` vs `nodes`: pass raw Markdown or pre-parsed nodes (from `parseMarkdownToStructure`).
281
282
  - `max-live-nodes`: `320` (default virtualization) or `0` (incremental batches).
282
283
  - `batchRendering`: fine-tune batches with `initialRenderBatchSize`, `renderBatchSize`, `renderBatchDelay`, `renderBatchBudgetMs`.
283
- - `enableMermaid` / `enableKatex` / `enableMonaco`: opt-in heavy deps when needed.
284
+ - `enableMermaid` / `enableKatex`: (re)enable heavy peers or custom loaders when needed (pairs with `disableMermaid` / `disableKatex`).
284
285
  - `parse-options`: reuse parser hooks (e.g., `preTransformTokens`, `requireClosingStrong`) on the component.
285
286
  - `final`: marks end-of-stream; disables mid-state loading parsing and forces unfinished constructs to settle.
286
287
  - `custom-html-tags`: extend streaming HTML allowlist for custom tags and emit them as custom nodes for `setCustomComponents` (e.g., `['thinking']`).
287
- - `custom-components`: register inline Vue components for custom tags/markers.
288
+ - `setCustomComponents(customId?, mapping)`: register inline Vue components for custom tags/markers (scoped by `custom-id` when provided).
288
289
 
289
- Example: map Markdown placeholders to Vue components
290
+ Example: map Markdown placeholders to Vue components (scoped)
290
291
 
291
292
  ```ts
292
293
  import { setCustomComponents } from 'markstream-vue'
293
294
 
294
- setCustomComponents({
295
+ setCustomComponents('docs', {
295
296
  CALLOUT: () => import('./components/Callout.vue'),
296
297
  })
297
298
 
298
299
  // Markdown: [[CALLOUT:warning title="Heads up" body="Details here"]]
299
300
  ```
300
301
 
301
- Or pass per-renderer:
302
+ Use the same `custom-id` on the renderer:
302
303
 
303
304
  ```vue
304
305
  <MarkdownRender
305
306
  :content="doc"
306
- :custom-components="{
307
- CALLOUT: () => import('./components/Callout.vue'),
308
- }"
307
+ custom-id="docs"
309
308
  />
310
309
  ```
311
310
 
@@ -334,7 +333,7 @@ Parse hooks example (match server + client):
334
333
  - Mermaid/KaTeX not rendering? Install the peer (`mermaid` / `katex`) and pass `:enable-mermaid="true"` / `:enable-katex="true"` or call the loader setters. If you load them via CDN script tags, the library will also pick up `window.mermaid` / `window.katex`.
335
334
  - CDN + KaTeX worker: if you don't bundle `katex` but still want off-main-thread rendering, create and inject a worker that loads KaTeX via CDN (UMD) using `createKaTeXWorkerFromCDN()` + `setKaTeXWorker()`.
336
335
  - Bundle size: peers are optional and not bundled; import only `markstream-vue/index.css` once. Use Shiki (`MarkdownCodeBlockNode`) when Monaco is too heavy.
337
- - Custom UI: register components via `setCustomComponents` (global) or `custom-components` prop, then emit markers/placeholders in Markdown and map them to Vue components.
336
+ - Custom UI: register components via `setCustomComponents` (global or scoped), then emit markers/placeholders in Markdown and map them to Vue components.
338
337
 
339
338
  ## 🆚 Why markstream-vue over a typical Markdown renderer?
340
339
 
package/README.zh-CN.md CHANGED
@@ -101,7 +101,7 @@ createApp({
101
101
  }).mount('#app')
102
102
  ```
103
103
 
104
- 确保在 CSS reset(如 `@tailwind base` 或 `@unocss/reset`)之后导入 `markstream-vue/index.css`,最好放在 `@layer components` 中以避免 Tailwind/UnoCSS 覆盖组件样式。根据需求再按需安装可选 peer 依赖:`stream-monaco`(Monaco 代码块)、`shiki`(Shiki 高亮)、`mermaid`(Mermaid 图表)、`katex`(数学公式)。
104
+ 确保在 CSS reset(如 `@tailwind base` 或 `@unocss/reset`)之后导入 `markstream-vue/index.css`,最好放在 `@layer components` 中以避免 Tailwind/UnoCSS 覆盖组件样式。根据需求再按需安装可选 peer 依赖:`stream-monaco`(Monaco 代码块)、`shiki` + `stream-markdown`(Shiki 高亮)、`mermaid`(Mermaid 图表)、`katex`(数学公式)。
105
105
 
106
106
  渲染器的 CSS 会作用于内部 `.markstream-vue` 容器下,以尽量降低对全局的影响;如果你脱离 `MarkdownRender` 单独使用导出的节点组件,请在外层包一层带 `markstream-vue` 类名的容器。
107
107
 
@@ -112,6 +112,7 @@ createApp({
112
112
  ```ts
113
113
  import { enableKatex, enableMermaid } from 'markstream-vue'
114
114
  import 'markstream-vue/index.css'
115
+ import 'katex/dist/katex.min.css'
115
116
 
116
117
  // 安装对应 peer 后再启用
117
118
  enableMermaid()
@@ -281,32 +282,30 @@ function addChunk(chunk: string) {
281
282
  - `content` 与 `nodes`:传原始 Markdown 或预解析节点(来自 `parseMarkdownToStructure`)。
282
283
  - `max-live-nodes`:`320`(默认虚拟化)或 `0`(增量批次)。
283
284
  - `batchRendering`:用 `initialRenderBatchSize`、`renderBatchSize`、`renderBatchDelay`、`renderBatchBudgetMs` 微调批次。
284
- - `enableMermaid` / `enableKatex` / `enableMonaco`:按需启用重型依赖。
285
+ - `enableMermaid` / `enableKatex`:用于(重新)启用重型依赖或自定义 loader(可与 `disableMermaid` / `disableKatex` 配合)。
285
286
  - `parse-options`:在组件上复用解析钩子(如 `preTransformTokens`、`requireClosingStrong`)。
286
287
  - `final`:标记“最终态/流结束”,关闭中间态 loading 解析并强制收敛未闭合结构。
287
288
  - `custom-html-tags`:扩展流式 HTML 白名单并将这些标签输出为自定义节点,便于 `setCustomComponents` 直接映射(如 `['thinking']`)。
288
- - `custom-components`:为自定义标签/标记注册内嵌 Vue 组件。
289
+ - `setCustomComponents(customId?, mapping)`:为自定义标签/标记注册内嵌 Vue 组件(传 `custom-id` 可限定作用域)。
289
290
 
290
- 示例:将 Markdown 占位符映射到 Vue 组件
291
+ 示例:将 Markdown 占位符映射到 Vue 组件(作用域)
291
292
 
292
293
  ```ts
293
294
  import { setCustomComponents } from 'markstream-vue'
294
295
 
295
- setCustomComponents({
296
+ setCustomComponents('docs', {
296
297
  CALLOUT: () => import('./components/Callout.vue'),
297
298
  })
298
299
 
299
300
  // Markdown: [[CALLOUT:warning title="提示" body="具体内容"]]
300
301
  ```
301
302
 
302
- 或在组件上按需传入:
303
+ 渲染时使用同一个 `custom-id`:
303
304
 
304
305
  ```vue
305
306
  <MarkdownRender
306
307
  :content="doc"
307
- :custom-components="{
308
- CALLOUT: () => import('./components/Callout.vue'),
309
- }"
308
+ custom-id="docs"
310
309
  />
311
310
  ```
312
311
 
@@ -335,7 +334,7 @@ setCustomComponents({
335
334
  - Mermaid / KaTeX 不显示?安装对应 peer(`mermaid` / `katex`),并传入 `:enable-mermaid="true"` / `:enable-katex="true"` 或调用 loader 设置函数。如果你是用 CDN `<script>` 引入,库也会自动读取 `window.mermaid` / `window.katex`。
336
335
  - CDN + KaTeX worker:如果你不打包 `katex` 但仍希望公式在 worker 中渲染(不占主线程),可以用 `createKaTeXWorkerFromCDN()` 创建一个“CDN 加载 KaTeX”的 worker,然后通过 `setKaTeXWorker()` 注入。
337
336
  - 体积问题:可选 peer 不会被打包,CSS 只需导入一次;对代码块可用 Shiki(`MarkdownCodeBlockNode`)替代 Monaco 以减轻体积。
338
- - 自定义 UI:通过 `setCustomComponents`(全局)或 `custom-components` prop 注册组件,在 Markdown 中放置占位标记并映射到 Vue 组件。
337
+ - 自定义 UI:通过 `setCustomComponents`(全局或作用域)注册组件,在 Markdown 中放置占位标记并映射到 Vue 组件。
339
338
 
340
339
  ## 🆚 为什么选择 markstream-vue,而不是普通 Markdown 渲染器?
341
340