99 useId ,
1010 useMemo ,
1111 useRef ,
12- useState ,
1312} from 'react' ;
1413import { type Options } from 'react-markdown' ;
14+ import { type RemendOptions } from 'remend' ;
1515import type { Pluggable , PluggableList } from 'unified' ;
1616
1717import { createBlockLexer } from './blockLexer' ;
@@ -224,17 +224,18 @@ interface StreamdownBlocksProps {
224224 content : string ;
225225 granularity : StreamAnimationGranularity ;
226226 markdownOptions : Omit < Options , 'children' > ;
227+ remendOptions ?: RemendOptions ;
227228 tailUnitsRef : { current : number } ;
228229}
229230
230231const StreamdownBlocks = memo < StreamdownBlocksProps > (
231- ( { content : smoothedContent , granularity, markdownOptions, tailUnitsRef } ) => {
232+ ( { content : smoothedContent , granularity, markdownOptions, remendOptions , tailUnitsRef } ) => {
232233 const profiler = useStreamdownProfiler ( ) ;
233234 const { components : baseComponents , ...rest } = markdownOptions ;
234235 const baseRehypePlugins = useStablePlugins ( markdownOptions . rehypePlugins ?? EMPTY_PLUGINS ) ;
235236 const remarkPlugins = useStablePlugins ( markdownOptions . remarkPlugins ?? EMPTY_PLUGINS ) ;
236237 const generatedId = useId ( ) ;
237- const [ lexBlocks ] = useState ( createBlockLexer ) ;
238+ const lexBlocks = useMemo ( ( ) => createBlockLexer ( remendOptions ) , [ remendOptions ] ) ;
238239
239240 const components = useMemo < Options [ 'components' ] > (
240241 ( ) => ( { ...baseComponents , [ STREAM_TAIL_TAG ] : StreamTail } ) as Options [ 'components' ] ,
@@ -444,6 +445,11 @@ export interface StreamdownProps extends Omit<Options, 'children'> {
444445 */
445446 latexGuard ?: boolean ;
446447 preprocess ?: ( text : string ) => string ;
448+ /**
449+ * Options for the remend pass that completes the open tail block, e.g.
450+ * `{ htmlTags: false }` when `<` is prose or math rather than HTML.
451+ */
452+ remend ?: RemendOptions ;
447453 smoothing ?: StreamSmoothingPreset ;
448454}
449455
@@ -452,15 +458,17 @@ export interface StreamdownProps extends Omit<Options, 'children'> {
452458// a memoized child keyed on the smoother's output — so the expensive block
453459// pipeline runs per reveal commit, not per chunk AND per commit.
454460export const Streamdown = memo < StreamdownProps > (
455- ( { content, granularity = 'char' , latexGuard = false , preprocess, smoothing, ...rest } ) => {
461+ ( { content, granularity = 'char' , latexGuard = false , preprocess, remend , smoothing, ...rest } ) => {
456462 const preprocessed = useMemo (
457463 ( ) => ( preprocess ? preprocess ( content ) : content ) ,
458464 [ content , preprocess ] ,
459465 ) ;
460466 const guardedContent = useLatexGuard ( preprocessed , latexGuard ) ;
461467 const tailUnitsRef = useRef ( 0 ) ;
468+ const remendOptions = useStableValue ( remend ) ;
462469 const smoothedContent = useSmoothStreamContent ( guardedContent , {
463470 preset : smoothing ?? 'balanced' ,
471+ remend : remendOptions ,
464472 tailUnitsRef,
465473 } ) ;
466474 const markdownOptions = useStableValue ( rest ) ;
@@ -470,6 +478,7 @@ export const Streamdown = memo<StreamdownProps>(
470478 content = { smoothedContent }
471479 granularity = { granularity }
472480 markdownOptions = { markdownOptions }
481+ remendOptions = { remendOptions }
473482 tailUnitsRef = { tailUnitsRef }
474483 />
475484 ) ;
0 commit comments