markdown-to-jsx 9.5.7 → 9.6.1

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
@@ -45,6 +45,7 @@ Some special features of the library:
45
45
  - [options.wrapperProps](#optionswrapperprops)
46
46
  - [Syntax highlighting](#syntax-highlighting)
47
47
  - [Handling shortcodes](#handling-shortcodes)
48
+ - [Streaming Markdown](#streaming-markdown)
48
49
  - [Usage with Preact](#usage-with-preact)
49
50
  - [AST Anatomy](#ast-anatomy)
50
51
  - [Node Types](#node-types)
@@ -430,6 +431,7 @@ const normalizedMarkdown2 = astToMarkdown(ast)
430
431
  | `renderRule` | `function` | - | Custom rendering for AST rules. See [renderRule](#optionsrenderrule) for details. |
431
432
  | `sanitizer` | `function` | built-in | Custom URL sanitizer function. See [sanitizer](#optionssanitizer) for details. |
432
433
  | `slugify` | `function` | built-in | Custom slug generation for heading IDs. See [slugify](#optionsslugify) for details. |
434
+ | `optimizeForStreaming` | `boolean` | `false` | Suppress rendering of incomplete markdown syntax for streaming. See [Streaming Markdown](#streaming-markdown) for details. |
433
435
  | `tagfilter` | `boolean` | `true` | Escape dangerous HTML tags (`script`, `iframe`, `style`, etc.) to prevent XSS. |
434
436
  | `wrapper` | `string \| component \| null` | `'div'` | Wrapper element for multiple children (React/React Native/Vue only). See [wrapper](#optionswrapper) for details. |
435
437
  | `wrapperProps` | `object` | - | Props for wrapper element (React/React Native/Vue only). See [wrapperProps](#optionswrapperprops) for details. |
@@ -835,6 +837,35 @@ function Example() {
835
837
 
836
838
  When you use `options.renderRule`, any React-renderable JSX may be returned including images and GIFs. Ensure you benchmark your solution as the `text` rule is one of the hottest paths in the system!
837
839
 
840
+ ### Streaming Markdown
841
+
842
+ When rendering markdown content that arrives incrementally (e.g., from an AI/LLM API, WebSocket, or Server-Sent Events), you may notice raw markdown syntax briefly appearing before it renders properly. This happens because incomplete syntax like `**bold text` or `<CustomComponent>partial content` gets rendered as text before the closing delimiter arrives.
843
+
844
+ The `optimizeForStreaming` option solves this by detecting incomplete markdown structures and returning `null` (React) or empty string (HTML) until the content is complete:
845
+
846
+ ```tsx
847
+ import Markdown from 'markdown-to-jsx/react'
848
+
849
+ function StreamingMarkdown({ content }) {
850
+ return <Markdown options={{ optimizeForStreaming: true }}>{content}</Markdown>
851
+ }
852
+ ```
853
+
854
+ **What it suppresses:**
855
+
856
+ - Unclosed HTML tags (`<div>content` without `</div>`)
857
+ - Incomplete tag syntax (`<div attr="value` without closing `>`)
858
+ - Unclosed HTML comments (`<!-- comment` without `-->`)
859
+ - Unclosed inline code (`` `code `` without closing backtick)
860
+ - Unclosed bold/italic (`**text` or `*text` without closing)
861
+ - Unclosed strikethrough (`~~text` without closing `~~`)
862
+ - Unclosed links (`[text](url` without closing `)`)
863
+ - Incomplete tables (header and separator row without any data rows)
864
+
865
+ **What renders normally (content visible as it streams):**
866
+
867
+ - Fenced code blocks - content is displayed as it arrives, waiting for closing fence
868
+
838
869
  ### Usage with Preact
839
870
 
840
871
  Everything will work just fine! Simply [Alias `react` to `preact/compat`](https://preactjs.com/guide/v10/switching-to-preact#setting-up-compat) like you probably already are doing.