markstream-react 0.0.52 → 0.0.53
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 +43 -6
- package/dist/Tooltip-DSM4ImfZ.js +207 -0
- package/dist/codeBlockExtraProps-RaPzFq78.js +3 -0
- package/dist/index-D0DspXy9.js +85 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.px.css +1 -1
- package/dist/index.tailwind.css +1 -1
- package/dist/markstream-react.css +1 -1
- package/dist/next.d.ts +41 -18
- package/dist/next.js +1 -1
- package/dist/server.d.ts +28 -5
- package/dist/server.js +1 -1
- package/dist/tailwind.cjs +1 -1
- package/dist/tailwind.js +1 -1
- package/dist/types/components/HtmlInlineNode/HtmlInlineNode.d.ts +4 -1
- package/dist/types/components/NodeRenderer.d.ts +2 -1
- package/dist/types/customComponents.d.ts +20 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/next.d.ts +7 -3
- package/dist/types/renderers/renderNode.d.ts +1 -1
- package/dist/types/server-renderer/index.d.ts +6 -2
- package/dist/types/server.d.ts +2 -2
- package/dist/types/types.d.ts +8 -3
- package/dist/types/utils/customHtmlTag.d.ts +5 -4
- package/dist/types/utils/htmlToReact.d.ts +17 -6
- package/package.json +6 -6
- package/dist/Tooltip-Ux2h3oiV.js +0 -207
- package/dist/codeBlockExtraProps-NhTjbA1T.js +0 -3
- package/dist/index-DdaK6qko.js +0 -85
package/README.md
CHANGED
|
@@ -165,26 +165,63 @@ module.exports = {
|
|
|
165
165
|
|
|
166
166
|
## Custom Components
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
For HTML-like custom tags in new React code, prefer renderer-local component maps:
|
|
169
|
+
|
|
170
|
+
- `streamingComponents` receives parser-backed `NodeComponentProps`, including `node.attrs`, `node.content`, and `node.loading`.
|
|
171
|
+
- `htmlComponents` renders through the raw/dynamic HTML path and receives normal React props plus `children`.
|
|
169
172
|
|
|
170
173
|
```tsx
|
|
171
174
|
import type { NodeComponentProps } from 'markstream-react'
|
|
172
|
-
import
|
|
175
|
+
import type React from 'react'
|
|
176
|
+
import MarkdownRender from 'markstream-react'
|
|
173
177
|
|
|
174
|
-
function
|
|
175
|
-
return <
|
|
178
|
+
function DocumentLink(props: NodeComponentProps<{ type: 'documentlink', content: string, loading?: boolean }>) {
|
|
179
|
+
return <span aria-busy={props.node.loading || undefined}>{props.node.content}</span>
|
|
176
180
|
}
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
function Badge({ kind, children }: React.PropsWithChildren<{ kind?: string }>) {
|
|
183
|
+
return <span data-kind={kind}>{children}</span>
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const renderer = (
|
|
187
|
+
<MarkdownRender
|
|
188
|
+
content={content}
|
|
189
|
+
final={isDone}
|
|
190
|
+
streamingComponents={{ documentlink: DocumentLink }}
|
|
191
|
+
htmlComponents={{ badge: Badge }}
|
|
192
|
+
/>
|
|
193
|
+
)
|
|
179
194
|
```
|
|
180
195
|
|
|
196
|
+
`streamingComponents` keys are normalized and automatically added to the parser's effective `customHtmlTags`, so incomplete tags can render while content is streaming.
|
|
197
|
+
|
|
198
|
+
`customHtmlTags` remains available as a lower-level parser option. `setCustomComponents` and `customId` also remain supported for compatibility, shared application-level registration, and existing node overrides:
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
import MarkdownRender, { setCustomComponents } from 'markstream-react'
|
|
202
|
+
|
|
203
|
+
setCustomComponents('chat', {
|
|
204
|
+
documentlink: DocumentLink,
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
const legacyRenderer = (
|
|
208
|
+
<MarkdownRender
|
|
209
|
+
customId="chat"
|
|
210
|
+
customHtmlTags={['documentlink']}
|
|
211
|
+
content={content}
|
|
212
|
+
/>
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Without `customHtmlTags` or `streamingComponents`, registered tag components render through the raw HTML path and receive HTML-style props/children instead of `props.node`. HTML safety is still handled by `htmlPolicy` and sanitization; the API split is not a security boundary.
|
|
217
|
+
|
|
181
218
|
## When Not to Use It
|
|
182
219
|
|
|
183
220
|
Use `react-markdown`, `marked`, or `markdown-it` when you only render short static Markdown, need the smallest possible Markdown stack, or already have a complete remark/rehype pipeline and do not need streaming mid-state handling.
|
|
184
221
|
|
|
185
222
|
## Type Exports
|
|
186
223
|
|
|
187
|
-
The package root exports the public component and renderer types, including `NodeRendererProps`, `NodeComponentProps`, `RenderContext`, `RenderNodeFn`, `CustomComponentMap`, and code-block option types.
|
|
224
|
+
The package root exports the public component and renderer types, including `NodeRendererProps`, `NodeComponentProps`, `StreamingComponentMap`, `HtmlComponentMap`, `RenderContext`, `RenderNodeFn`, `CustomComponentMap`, and code-block option types.
|
|
188
225
|
|
|
189
226
|
## Development
|
|
190
227
|
|