@@ -293,10 +293,12 @@ fn test_table_cjk_alignment() {
293293
294294#[ test]
295295fn test_mermaid_block_detection ( ) {
296- // Mermaid rendering is temporarily disabled by default, so Mermaid fences
297- // should safely fall back to normal code blocks unless explicitly opted in .
296+ // Without a native image protocol, Mermaid fences stay useful as readable
297+ // source code instead of becoming a half-block image or a text stub .
298298 let md = "```mermaid\n flowchart LR\n A --> B\n ```" ;
299- let lines = render_markdown ( md) ;
299+ let lines = with_mermaid_rendering_override ( Some ( true ) , || {
300+ mermaid:: with_image_protocol_override ( Some ( false ) , || render_markdown ( md) )
301+ } ) ;
300302 let text: String = lines
301303 . iter ( )
302304 . flat_map ( |l| l. spans . iter ( ) . map ( |s| s. content . as_ref ( ) ) )
@@ -310,6 +312,64 @@ fn test_mermaid_block_detection() {
310312 text. contains( "flowchart LR" ) ,
311313 "Expected raw Mermaid source: {text}"
312314 ) ;
315+ assert ! (
316+ lines. iter( ) . all( |line| {
317+ mermaid:: parse_image_placeholder( line) . is_none( )
318+ && mermaid:: parse_inline_image_placeholder( line) . is_none( )
319+ } ) ,
320+ "Unsupported terminals must not receive a Mermaid image placeholder: {text}"
321+ ) ;
322+ }
323+
324+ #[ cfg( feature = "mermaid-renderer" ) ]
325+ #[ test]
326+ fn lazy_mermaid_without_native_protocol_also_renders_source ( ) {
327+ let md = "```mermaid\n flowchart TD\n Start --> Finish\n ```" ;
328+ let lines = with_mermaid_rendering_override ( Some ( true ) , || {
329+ mermaid:: with_image_protocol_override ( Some ( false ) , || {
330+ render_markdown_lazy ( md, Some ( 80 ) , 0 ..usize:: MAX )
331+ } )
332+ } ) ;
333+ let text = lines_to_string ( & lines) ;
334+
335+ assert ! ( text. contains( "┌─ mermaid" ) , "missing source header: {text}" ) ;
336+ assert ! ( text. contains( "Start --> Finish" ) , "missing source: {text}" ) ;
337+ assert ! ( lines. iter( ) . all( |line| {
338+ mermaid:: parse_image_placeholder( line) . is_none( )
339+ && mermaid:: parse_inline_image_placeholder( line) . is_none( )
340+ } ) ) ;
341+ }
342+
343+ #[ test]
344+ fn streaming_mermaid_without_native_protocol_keeps_source_visible ( ) {
345+ let md = "```mermaid\n flowchart TD\n Stream --> Source\n ```" ;
346+ let lines = with_mermaid_rendering_override ( Some ( true ) , || {
347+ mermaid:: with_image_protocol_override ( Some ( false ) , || {
348+ with_streaming_render_context ( || render_markdown_with_width ( md, Some ( 80 ) ) )
349+ } )
350+ } ) ;
351+ let text = lines_to_string ( & lines) ;
352+
353+ assert ! ( text. contains( "┌─ mermaid" ) , "missing source header: {text}" ) ;
354+ assert ! ( text. contains( "Stream --> Source" ) , "missing source: {text}" ) ;
355+ assert ! ( !text. contains( "rendering mermaid diagram" ) , "{text}" ) ;
356+ assert ! ( lines. iter( ) . all( |line| {
357+ mermaid:: parse_image_placeholder( line) . is_none( )
358+ && mermaid:: parse_inline_image_placeholder( line) . is_none( )
359+ } ) ) ;
360+ }
361+
362+ #[ cfg( feature = "mermaid-renderer" ) ]
363+ #[ test]
364+ fn mermaid_gate_accepts_native_protocol_and_rejects_halfblock_fallback ( ) {
365+ with_mermaid_rendering_override ( Some ( true ) , || {
366+ mermaid:: with_image_protocol_override ( Some ( false ) , || {
367+ assert ! ( !should_render_mermaid_block( Some ( "mermaid" ) ) ) ;
368+ } ) ;
369+ mermaid:: with_image_protocol_override ( Some ( true ) , || {
370+ assert ! ( should_render_mermaid_block( Some ( "mermaid" ) ) ) ;
371+ } ) ;
372+ } ) ;
313373}
314374
315375#[ test]
0 commit comments