// This file is auto-generated by scripts/generate_syntax_tests.py
// DO NOT EDIT MANUALLY

#[cfg(test)]
#[allow(dead_code, unused_imports, unused)]
mod generated_syntax_tests {
    use wasot_compiler::events::{Event, Emitter};
    use wasot_compiler::parsers::wasot::{Footnote, Link, MetaLine, QuotedString, Id};
    use wasot_compiler::emitters::wasot_file_emitter::WasotFileEmitter;
    use wasot_compiler::parsers::wasot::arguments::ParsedArguments;
    use std::sync::mpsc;
    use std::collections::HashMap;


    mod test_format {
        use super::*;

        #[test]
        fn simple_paragraph() {
            // Test a basic single-level block with text content.
            let input = ".paragraph\nThis is a simple paragraph.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This is a simple paragraph.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_block() {
            // Test a block with no text content.
            let input = ".empty";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "empty");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_inline_text() {
            // Test a block that has inline text defined on the meta line.
            let input = ".heading This is the heading text\nSome body content here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "heading");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "This is the heading text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some body content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn block_with_arguments() {
            // Test a block with positional arguments and keyword arguments.
            let input = ".div .. theme=\"primary\" section=\"main\"\nContent inside the div.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "theme").unwrap().1.content, "primary");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "section").unwrap().1.content, "main");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content inside the div.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn block_with_id() {
            // Test a block with an ID specified using the colon syntax.
            let input = ".section :intro-section\nWelcome to our documentation.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "intro-section");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Welcome to our documentation.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn nested_blocks() {
            // Test multiple levels of nested blocks.
            let input = ".outer\nOuter block text.\n..inner\nInner block text.\n...deeply-nested\nVery deep text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 9, "Expected 9 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Outer block text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "inner");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Inner block text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "deeply-nested");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Very deep text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
        }

        #[test]
        fn quoted_block_type() {
            // Test a block type that contains spaces and requires quotes.
            let input = ".\"code block\" language=\"python\"\nprint(\"Hello, World!\")";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "code block");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "language=\"python\"");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "print(\"Hello, World!\")");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn mixed_arguments() {
            // Test a block with both positional and keyword arguments.
            let input = ".button primary large .. disabled=true title=\"Click me\"\nSubmit";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "button");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "primary large ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "disabled").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "title").unwrap().1.content, "Click me");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Submit");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn self_closing_block() {
            // Test a self-closing block using the .# syntax.
            let input = ".# Page Title";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Page Title");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn complex_inline_and_parameters() {
            // Test a block with inline text, ID, and parameters all together.
            let input = ".alert Warning message .. type=\"danger\" dismissible=true :alert-1\nThis is an important alert that can be dismissed.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "alert");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "alert-1");
                    assert_eq!(meta_line.inline_text.content, "Warning message ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "danger");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "dismissible").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This is an important alert that can be dismissed.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_numbers() {
            // Test block types that contain numbers.
            let input = ".h1\n.block123";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "h1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "block123");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_special_characters() {
            // Test block types containing dashes and underscores.
            let input = ".type-name\nContent for type-name.\n.type_name\nContent for type_name.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type-name");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content for type-name.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type_name");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content for type_name.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn quoted_block_type_with_spaces() {
            // Test quoted block types that contain spaces.
            let input = ".\"my block type\"\nContent for custom block type.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "my block type");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content for custom block type.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn heading_blocks_with_hash() {
            // Test special heading syntax using # characters.
            let input = ".##\n.### Deep Section";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "##");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "###");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Deep Section");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn just_a_dot_block() {
            // Test a single dot with no type creates an empty-type block.
            let input = ".\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
        }

        #[test]
        fn empty_parameters() {
            // Test blocks with empty parameter sections.
            let input = ".div text ..\nSome content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text ");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_positional_arguments() {
            // Test blocks with multiple positional arguments.
            let input = ".button .. primary large rounded\nClick me!";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "button");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "primary");
                    assert_eq!(meta_line.arguments.args[1].content, "large");
                    assert_eq!(meta_line.arguments.args[2].content, "rounded");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click me!");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn simple_keyword_arguments() {
            // Test blocks with basic keyword arguments.
            let input = ".div .. class=\"container\" id=\"main\"\nContent with kwargs.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "container");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "id").unwrap().1.content, "main");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with kwargs.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_keys_and_values() {
            // Test keyword arguments with quoted keys and values.
            let input = ".component .. \"my key\"=\"my value\" style=\"color: red;\"\nComponent content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "component");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "my key").unwrap().1.content, "my value");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "style").unwrap().1.content, "color: red;");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn mixed_arguments_order() {
            // Test mixing positional and keyword arguments.
            let input = ".widget .. primary enabled class=\"btn\" onclick=\"click()\"\nWidget content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "widget");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "primary");
                    assert_eq!(meta_line.arguments.args[1].content, "enabled");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "btn");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "onclick").unwrap().1.content, "click()");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Widget content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_colons_for_namespacing() {
            // Test IDs that contain colons for namespacing.
            let input = ".div :page:header:logo\nLogo content here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "page:header:logo");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Logo content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_special_characters() {
            // Test IDs with various special characters.
            let input = ".span :item-123_abc\n.div :test:namespace:id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "span");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "item-123_abc");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "test:namespace:id");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn block_type_starting_with_number() {
            // Test block types that start with numbers.
            let input = ".123class\nContent for numbered type.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "123class");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content for numbered type.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_block_type() {
            // Test quoted block types with escaped quotes inside.
            let input = ".\"type \\\"quoted\\\"\"\nContent for escaped quotes.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type \"quoted\"");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content for escaped quotes.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unicode_block_type() {
            // Test block types with Unicode characters.
            let input = ".日本語\nJapanese content.\n.café\nFrench content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "日本語");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Japanese content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "café");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "French content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn unclosed_quoted_block_type() {
            // Test handling of unclosed quotes in block types.
            let input = ".\"unclosed\nSome content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "\"unclosed");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_inline_text() {
            // Test IDs combined with inline text.
            let input = ".div Hello World :my-id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.inline_text.content, "Hello World");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_parameters() {
            // Test IDs combined with parameters.
            let input = ".div .. class=\"container\" :main-div\nDiv content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "main-div");
                    assert_eq!(meta_line.inline_text.quoted, false);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "container");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Div content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn everything_combined() {
            // Test all meta-line features together.
            let input = ".\"custom block\" \"Inline text\" .. arg1 \"arg 2\" key=\"value\" :my-id\nContent with everything.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "custom block");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.inline_text.content, "Inline text");
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg 2");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with everything.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_separators() {
            // Test multiple .. separators in parameters.
            let input = ".block .. param1 .. param2 .. param3\nBlock content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "block");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 5);
                    assert_eq!(meta_line.arguments.args[0].content, "param1");
                    assert_eq!(meta_line.arguments.args[1].content, "..");
                    assert_eq!(meta_line.arguments.args[2].content, "param2");
                    assert_eq!(meta_line.arguments.args[3].content, "..");
                    assert_eq!(meta_line.arguments.args[4].content, "param3");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Block content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_quoted_arguments() {
            // Test empty quoted arguments and values.
            let input = ".component .. \"\" key=\"\"\nComponent content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "component");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn arguments_with_special_characters() {
            // Test arguments containing special characters.
            let input = ".special .. @notify #hashtag url=\"https://example.com?foo=bar&baz=qux\"\nSpecial content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "special");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "@notify");
                    assert_eq!(meta_line.arguments.args[1].content, "#hashtag");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "url").unwrap().1.content, "https://example.com?foo=bar&baz=qux");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Special content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unicode_in_arguments() {
            // Test Unicode characters in argument keys and values.
            let input = ".widget .. キー=値 language=\"日本語\"\nUnicode content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "widget");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "キー").unwrap().1.content, "値");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "日本語");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Unicode content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_equals_in_value() {
            // Test values that contain equals signs.
            let input = ".equation .. formula=\"x=y+z\" expression=\"a=b=c\"\nMath content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "equation");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "formula").unwrap().1.content, "x=y+z");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "expression").unwrap().1.content, "a=b=c");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Math content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn interspersed_arguments() {
            // Test positional and keyword arguments mixed together.
            let input = ".mixed .. arg1 key1=val1 arg2 key2=val2 arg3\nMixed content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "mixed");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg2");
                    assert_eq!(meta_line.arguments.args[2].content, "arg3");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key1").unwrap().1.content, "val1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key2").unwrap().1.content, "val2");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Mixed content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_quoted_arguments() {
            // Test complex quoting in mixed arguments.
            let input = ".complex .. \"arg 1\" key=\"val 1\" \"key 2\"=\"val 2\"\nComplex content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "complex");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "arg 1");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "val 1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key 2").unwrap().1.content, "val 2");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Complex content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn simple_url_link() {
            // Test basic URL links in text content.
            let input = ".paragraph\nCheck out ((https://wasot.org)) for more info.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Check out ((https://wasot.org)) for more info.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn named_link() {
            // Test links with display names.
            let input = ".paragraph\nVisit ((Wasot Documentation|https://docs.wasot.org)) for details.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Visit ((Wasot Documentation|https://docs.wasot.org)) for details.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_reference_link() {
            // Test links to other blocks by ID.
            let input = ".paragraph\nSee the ((:introduction)) section below.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "See the ((:introduction)) section below.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_links_in_line() {
            // Test multiple links appearing in one line.
            let input = ".paragraph\nCheck ((https://wasot.org)) and ((https://github.com/wasot)) for more.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Check ((https://wasot.org)) and ((https://github.com/wasot)) for more.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn emoji_block_type() {
            // Test block types with complex Unicode including emojis.
            let input = ".émojis👨‍👩‍👧‍👦\nContent with emoji block type.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "émojis👨‍👩‍👧‍👦");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with emoji block type.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_id() {
            // Test blocks with empty ID syntax.
            let input = ".div :\nContent with empty ID.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, ":");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with empty ID.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unicode_id() {
            // Test IDs with Unicode characters.
            let input = ".div :日本語id\nContent with Unicode ID.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "日本語id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with Unicode ID.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn basic_combinations_type_and_inline() {
            // Test basic combination of type and inline text.
            let input = ".div Hello World";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Hello World");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn basic_combinations_type_and_params() {
            // Test basic combination of type and parameters.
            let input = ".div .. class=\"container\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "container");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn basic_combinations_type_and_id() {
            // Test basic combination of type and ID.
            let input = ".div :my-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn empty_quoted_argument_value() {
            // Test keyword arguments with empty values.
            let input = ".widget .. key=\"\"\nWidget content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "widget");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Widget content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn arguments_with_equals_but_no_value() {
            // Test positional arguments that end with equals.
            let input = ".form .. submit=\nForm content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "form");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "submit").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Form content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multi_line_text_content() {
            // Test blocks with multiple lines of text.
            let input = ".story\nOnce upon a time,\nin a land far away,\nthere lived a parser.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "story");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Once upon a time,");
                    assert_eq!(lines[1], "in a land far away,");
                    assert_eq!(lines[2], "there lived a parser.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn advanced_links_with_arguments() {
            // Test links that contain arguments.
            let input = ".paragraph\nClick ((submit .. class=\"btn\" type=\"primary\")) to continue.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click ((submit .. class=\"btn\" type=\"primary\")) to continue.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn simple_block_types() {
            // Test basic block types like div, p, span.
            let input = ".div\n.p\n.span";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "p");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "span");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn heading_blocks() {
            // Test special heading syntax using hash characters.
            let input = ".#\n.##\n.###";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "##");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "###");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn empty_type_blocks() {
            // Test blocks with empty types using just dots.
            let input = ".\n..";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn empty_parameter_section() {
            // Test blocks with empty parameter sections after separator.
            let input = ".div text ..";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text ");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn multiple_parameter_separators() {
            // Test multiple .. separators in parameters.
            let input = ".div text .. p1 .. p2";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text ");
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "p1");
                    assert_eq!(meta_line.arguments.args[1].content, "..");
                    assert_eq!(meta_line.arguments.args[2].content, "p2");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn mixed_dots_in_parameters() {
            // Test parameter parsing with multiple dots.
            let input = ".div .. .. .. .. text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 4);
                    assert_eq!(meta_line.arguments.args[0].content, "..");
                    assert_eq!(meta_line.arguments.args[1].content, "..");
                    assert_eq!(meta_line.arguments.args[2].content, "..");
                    assert_eq!(meta_line.arguments.args[3].content, "text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn single_positional_argument() {
            // Test blocks with a single positional argument.
            let input = ".button .. primary\nButton text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "button");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "primary");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Button text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn three_positional_arguments() {
            // Test blocks with multiple positional arguments.
            let input = ".button .. primary large rounded\nClick me!";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "button");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "primary");
                    assert_eq!(meta_line.arguments.args[1].content, "large");
                    assert_eq!(meta_line.arguments.args[2].content, "rounded");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click me!");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn special_character_arguments() {
            // Test arguments containing various special characters.
            let input = ".component .. @#$%^&*()\nComponent content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "component");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "@#$%^&*()");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn simple_keyword_argument() {
            // Test basic keyword argument syntax.
            let input = ".element .. key=value\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_key_in_kwargs() {
            // Test keyword arguments with quoted keys.
            let input = ".element .. \"my key\"=value\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "my key").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_value_in_kwargs() {
            // Test keyword arguments with quoted values.
            let input = ".element .. key=\"my value\"\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "my value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn both_quoted_in_kwargs() {
            // Test keyword arguments with both key and value quoted.
            let input = ".element .. \"my key\"=\"my value\"\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "my key").unwrap().1.content, "my value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn special_chars_in_kwarg_value() {
            // Test keyword values with special characters.
            let input = ".element .. key=@#$%^&*()\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "@#$%^&*()");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_equals_in_kwarg_value() {
            // Test keyword values that contain equals signs.
            let input = ".element .. key=val=ue\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "val=ue");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unicode_in_kwargs() {
            // Test Unicode characters in keyword arguments.
            let input = ".element .. キー=値\nElement content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "element");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "キー").unwrap().1.content, "値");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Element content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn namespaced_id_with_document_prefix() {
            // Test IDs that use colon-separated namespacing with document prefix style.
            let input = ".div :docid:id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "docid:id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_numbers() {
            // Test IDs that contain numbers.
            let input = ".div :id123\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "id123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_dashes_and_underscores() {
            // Test IDs with dashes and underscores.
            let input = ".div :my-id_123\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id_123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_starting_with_number() {
            // Test IDs that start with numbers.
            let input = ".div :123id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "123id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_colons_in_id() {
            // Test IDs with multiple colons for namespacing.
            let input = ".div :namespace:id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "namespace:id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_id_syntax() {
            // Test blocks with empty ID syntax.
            let input = ".div :\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, ":");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unicode_id_characters() {
            // Test IDs with Unicode characters.
            let input = ".div :日本語id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "日本語id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn type_only_combination() {
            // Test basic type-only blocks.
            let input = ".div";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn type_and_inline_combination() {
            // Test basic combination of type and inline text.
            let input = ".div text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn type_and_params_combination() {
            // Test basic combination of type and parameters.
            let input = ".div .. params";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn type_and_id_combination() {
            // Test basic combination of type and ID.
            let input = ".div :id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn single_line_text_content() {
            // Test blocks with single line text content.
            let input = ".paragraph\nThis is a single line of text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This is a single line of text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_line_text_content() {
            // Test blocks with multiple lines of text content.
            let input = ".paragraph\nFirst line of text.\nSecond line of text.\nThird line of text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "First line of text.");
                    assert_eq!(lines[1], "Second line of text.");
                    assert_eq!(lines[2], "Third line of text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_text_content_block() {
            // Test blocks with no text content.
            let input = ".paragraph";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_with_inline_text_placement() {
            // Test IDs combined with inline text.
            let input = ".div text :id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "id");
                    assert_eq!(meta_line.inline_text.content, "text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_params_placement() {
            // Test IDs combined with parameters.
            let input = ".div .. params :id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "id");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_with_everything() {
            // Test IDs with inline text and parameters.
            let input = ".div text .. params :id\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "id");
                    assert_eq!(meta_line.inline_text.content, "text ");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn text_with_leading_whitespace() {
            // Test text content with leading and trailing whitespace.
            let input = ".paragraph\n   Text with leading spaces   ";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "   Text with leading spaces   ");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn very_long_text_line() {
            // Test handling of very long text lines.
            let input = ".paragraph\nThis is a very long line of text that contains many words and characters to test the parser's ability to handle long content without issues or memory problems when processing large amounts of text data in a single line.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This is a very long line of text that contains many words and characters to test the parser's ability to handle long content without issues or memory problems when processing large amounts of text data in a single line.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn block_with_no_children() {
            // Test blocks that have no child content.
            let input = ".container";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_text_children_only() {
            // Test blocks containing only text content.
            let input = ".article\nThis is the first paragraph.\nThis is the second paragraph.\nThis is the third paragraph.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "This is the first paragraph.");
                    assert_eq!(lines[1], "This is the second paragraph.");
                    assert_eq!(lines[2], "This is the third paragraph.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn block_with_block_children_only() {
            // Test blocks containing only nested blocks.
            let input = ".container\n..section\n..article\n..footer";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "footer");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn block_with_mixed_children() {
            // Test blocks with both text and nested block content.
            let input = ".article\nIntroduction text here.\n..section\nSection content.\nMore article text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Introduction text here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Section content.");
                    assert_eq!(lines[1], "More article text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn adjacent_text_lines() {
            // Test multiple adjacent text lines that get merged.
            let input = ".paragraph\nFirst line.\nSecond line.\nThird line.\n\nFourth line after gap.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 5);
                    assert_eq!(lines[0], "First line.");
                    assert_eq!(lines[1], "Second line.");
                    assert_eq!(lines[2], "Third line.");
                    assert_eq!(lines[3], "");
                    assert_eq!(lines[4], "Fourth line after gap.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn space_separated_tokenization() {
            // Test basic space-separated token parsing.
            let input = ".div .. arg1 arg2 arg3\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg2");
                    assert_eq!(meta_line.arguments.args[2].content, "arg3");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_tokens_with_spaces() {
            // Test tokenization of quoted strings containing spaces.
            let input = ".div .. \"arg with spaces\" \"another arg\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "arg with spaces");
                    assert_eq!(meta_line.arguments.args[1].content, "another arg");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_tokens_between_spaces() {
            // Test handling of multiple consecutive spaces creating empty tokens.
            let input = ".div .. arg1    arg2\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg2");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn tokens_with_equals_signs() {
            // Test tokenization when arguments contain equals signs.
            let input = ".div .. arg1=value arg2\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "arg2");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "arg1").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn mixed_quoted_and_unquoted_tokens() {
            // Test mixing quoted and unquoted tokens in parameters.
            let input = ".div .. unquoted \"quoted arg\" another\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "unquoted");
                    assert_eq!(meta_line.arguments.args[1].content, "quoted arg");
                    assert_eq!(meta_line.arguments.args[2].content, "another");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn nested_quotes_handling() {
            // Test handling of quotes within quoted strings.
            let input = ".div .. \"outer \\\"inner\\\" outer\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "outer \"inner\" outer");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quote_preservation_in_output() {
            // Test that quotes are properly preserved in tokenized output.
            let input = ".div .. key=\"\\\"quoted value\\\"\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "\"quoted value\"");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_arguments() {
            // Test handling of escaped quotes in argument parsing.
            let input = ".div .. arg=\\\"value\\\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "arg").unwrap().1.content, "\\value\\");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unclosed_quotes_fallback() {
            // Test parser behavior with unclosed quotes.
            let input = ".div .. \"unclosed quote arg\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "unclosed quote arg");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_quote_scenarios() {
            // Test complex quoting scenarios with mixed patterns.
            let input = ".div .. \"arg 1\" unquoted \"arg \\\"with\\\" quotes\" final\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 4);
                    assert_eq!(meta_line.arguments.args[0].content, "arg 1");
                    assert_eq!(meta_line.arguments.args[1].content, "unquoted");
                    assert_eq!(meta_line.arguments.args[2].content, "arg \"with\" quotes");
                    assert_eq!(meta_line.arguments.args[3].content, "final");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn split_on_first_equals_outside_quotes() {
            // Test equals tokenizer splitting on first equals sign.
            let input = ".div .. key=value=more\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value=more");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_keys_with_equals() {
            // Test equals parsing with quoted keys containing equals.
            let input = ".div .. \"key=with=equals\"=value\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "with=equals=value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_values_with_equals() {
            // Test equals parsing with quoted values containing equals.
            let input = ".div .. key=\"value=with=equals\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value=with=equals");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn no_equals_single_token() {
            // Test that tokens without equals remain as positional arguments.
            let input = ".div .. noequals\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "noequals");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_equals_parsing_scenarios() {
            // Test complex equals parsing with multiple patterns.
            let input = ".div .. arg1 key1=val1 arg2 \"key 2\"=\"val 2\" key3=val3=extra\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg2");
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key1").unwrap().1.content, "val1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key 2").unwrap().1.content, "val 2");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key3").unwrap().1.content, "val3=extra");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_dot_separators() {
            // Test ambiguous multiple dot separator handling.
            let input = ".div .. .. .. ..\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "..");
                    assert_eq!(meta_line.arguments.args[1].content, "..");
                    assert_eq!(meta_line.arguments.args[2].content, "..");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unclosed_quote_fallback() {
            // Test unclosed quote handling in block types.
            let input = ".\"unclosed quote text\nContent after unclosed quote.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "\"unclosed");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "quote text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content after unclosed quote.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_colon_id_patterns() {
            // Test handling of multiple colon patterns.
            let input = ".type :multiple :colons :here\nContent with multiple colons.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, ":multiple :colons");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with multiple colons.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_components() {
            // Test handling of empty components in meta-lines.
            let input = ".\"\" \"\" .. \"\" \"\"=\"\" :\nEmpty component content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.inline_text.content.is_empty());
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "");
                    assert_eq!(meta_line.arguments.args[1].content, ":");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Empty component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
        }

        #[test]
        fn whitespace_only_block_types() {
            // Test handling of whitespace-only block types.
            let input = ".\" \"\n.\"  \"\n.\"	\"\nContent with whitespace types.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 7, "Expected 7 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, " ");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "  ");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "	");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with whitespace types.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
        }

        #[test]
        fn edge_case_parameter_parsing() {
            // Test edge cases in parameter parsing.
            let input = ".test .. key= empty=\"\" =single\nEdge case content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "test");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "empty").unwrap().1.content, "");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "").unwrap().1.content, "single");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Edge case content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn mixed_separator_patterns() {
            // Test complex mixed separator patterns.
            let input = ".complex text .. .. param1 .. param2 .. .. param3\nComplex separator content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "complex");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text ");
                    assert_eq!(meta_line.arguments.args.len(), 7);
                    assert_eq!(meta_line.arguments.args[0].content, "..");
                    assert_eq!(meta_line.arguments.args[1].content, "param1");
                    assert_eq!(meta_line.arguments.args[2].content, "..");
                    assert_eq!(meta_line.arguments.args[3].content, "param2");
                    assert_eq!(meta_line.arguments.args[4].content, "..");
                    assert_eq!(meta_line.arguments.args[5].content, "..");
                    assert_eq!(meta_line.arguments.args[6].content, "param3");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Complex separator content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn large_number_of_arguments() {
            // Test handling of a large number of positional arguments.
            let input = ".test .. arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 arg27 arg28 arg29 arg30\nContent with many arguments.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "test");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 30);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg2");
                    assert_eq!(meta_line.arguments.args[2].content, "arg3");
                    assert_eq!(meta_line.arguments.args[3].content, "arg4");
                    assert_eq!(meta_line.arguments.args[4].content, "arg5");
                    assert_eq!(meta_line.arguments.args[5].content, "arg6");
                    assert_eq!(meta_line.arguments.args[6].content, "arg7");
                    assert_eq!(meta_line.arguments.args[7].content, "arg8");
                    assert_eq!(meta_line.arguments.args[8].content, "arg9");
                    assert_eq!(meta_line.arguments.args[9].content, "arg10");
                    assert_eq!(meta_line.arguments.args[10].content, "arg11");
                    assert_eq!(meta_line.arguments.args[11].content, "arg12");
                    assert_eq!(meta_line.arguments.args[12].content, "arg13");
                    assert_eq!(meta_line.arguments.args[13].content, "arg14");
                    assert_eq!(meta_line.arguments.args[14].content, "arg15");
                    assert_eq!(meta_line.arguments.args[15].content, "arg16");
                    assert_eq!(meta_line.arguments.args[16].content, "arg17");
                    assert_eq!(meta_line.arguments.args[17].content, "arg18");
                    assert_eq!(meta_line.arguments.args[18].content, "arg19");
                    assert_eq!(meta_line.arguments.args[19].content, "arg20");
                    assert_eq!(meta_line.arguments.args[20].content, "arg21");
                    assert_eq!(meta_line.arguments.args[21].content, "arg22");
                    assert_eq!(meta_line.arguments.args[22].content, "arg23");
                    assert_eq!(meta_line.arguments.args[23].content, "arg24");
                    assert_eq!(meta_line.arguments.args[24].content, "arg25");
                    assert_eq!(meta_line.arguments.args[25].content, "arg26");
                    assert_eq!(meta_line.arguments.args[26].content, "arg27");
                    assert_eq!(meta_line.arguments.args[27].content, "arg28");
                    assert_eq!(meta_line.arguments.args[28].content, "arg29");
                    assert_eq!(meta_line.arguments.args[29].content, "arg30");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with many arguments.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn large_number_of_child_blocks() {
            // Test blocks with many child elements.
            let input = ".container\n..child1\n..child2\n..child3\n..child4\n..child5\n..child6\n..child7\n..child8\n..child9\n..child10\n..child11\n..child12\n..child13\n..child14\n..child15\nFinal child content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 33, "Expected 33 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child3");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child4");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child5");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
            
            // Event 11
            match &events[11] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child6");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child7");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child8");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            match &events[17] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child9");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 17, got {:?}", events[17]),
            }
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            match &events[19] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child10");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            assert!(matches!(&events[20], Event::BlockFinished));
            
            // Event 21
            match &events[21] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child11");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            match &events[23] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child12");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 23, got {:?}", events[23]),
            }
            
            // Event 24
            assert!(matches!(&events[24], Event::BlockFinished));
            
            // Event 25
            match &events[25] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child13");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 25, got {:?}", events[25]),
            }
            
            // Event 26
            assert!(matches!(&events[26], Event::BlockFinished));
            
            // Event 27
            match &events[27] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child14");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 27, got {:?}", events[27]),
            }
            
            // Event 28
            assert!(matches!(&events[28], Event::BlockFinished));
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child15");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            match &events[30] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Final child content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 30, got {:?}", events[30]),
            }
            
            // Event 31
            assert!(matches!(&events[31], Event::BlockFinished));
            
            // Event 32
            assert!(matches!(&events[32], Event::BlockFinished));
        }

        #[test]
        fn maximum_reasonable_nesting_depth() {
            // Test maximum reasonable nesting depth without hitting limits.
            let input = ".level1\n..level2\n...level3\n....level4\n.....level5\n......level6\n.......level7\n........level8\n.........level9\n..........level10\nContent at maximum depth.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 21, "Expected 21 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level4");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level5");
                    assert_eq!(meta_line.level, 5);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level6");
                    assert_eq!(meta_line.level, 6);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level7");
                    assert_eq!(meta_line.level, 7);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level8");
                    assert_eq!(meta_line.level, 8);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level9");
                    assert_eq!(meta_line.level, 9);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level10");
                    assert_eq!(meta_line.level, 10);
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content at maximum depth.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            assert!(matches!(&events[19], Event::BlockFinished));
            
            // Event 20
            assert!(matches!(&events[20], Event::BlockFinished));
        }

        #[test]
        fn very_long_block_type_names() {
            // Test handling of very long block type names.
            let input = ".very-long-block-type-name-that-exceeds-normal-expectations-for-block-type-length-but-should-still-be-handled-correctly\nContent with very long block type.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "very-long-block-type-name-that-exceeds-normal-expectations-for-block-type-length-but-should-still-be-handled-correctly");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with very long block type.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_nested_structures_with_siblings() {
            // Test complex nesting with multiple siblings at each level.
            let input = ".root\n..branch1\n...leaf1\n...leaf2\n..branch2\n...leaf3\n...leaf4\n..branch3\n...leaf5\nFinal nested content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 19, "Expected 19 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "root");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf1");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf2");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf4");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch3");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf5");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            match &events[15] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Final nested content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
        }

        #[test]
        fn mixed_line_ending_types() {
            // Test handling of different line ending types.
            let input = ".mixed-endings\nLine with LF ending.\nLine with potential CR handling.\nLine with mixed content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "mixed-endings");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Line with LF ending.");
                    assert_eq!(lines[1], "Line with potential CR handling.");
                    assert_eq!(lines[2], "Line with mixed content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_whitespace_handling() {
            // Test various whitespace scenarios.
            let input = ".whitespace   \n	Content with tabs and trailing spaces.  \n   Content with leading spaces.\nContent with normal spacing.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "whitespace");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "  ");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "	Content with tabs and trailing spaces.  ");
                    assert_eq!(lines[1], "   Content with leading spaces.");
                    assert_eq!(lines[2], "Content with normal spacing.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn error_recovery_patterns() {
            // Test parser recovery from malformed syntax.
            let input = ".valid\nValid content.\nnot a meta line\n.another-valid\nMore valid content after error.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "valid");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Valid content.");
                    assert_eq!(lines[1], "not a meta line");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "another-valid");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "More valid content after error.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn boundary_unicode_characters() {
            // Test Unicode boundary characters and combining sequences.
            let input = ".unicode-test\nContent with ñoéü characters.\nContent with 🌟⭐✨ emojis.\nContent with αβγδε Greek letters.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "unicode-test");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Content with ñoéü characters.");
                    assert_eq!(lines[1], "Content with 🌟⭐✨ emojis.");
                    assert_eq!(lines[2], "Content with αβγδε Greek letters.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn complex_quote_nesting_scenarios() {
            // Test deeply nested quote scenarios in arguments.
            let input = ".complex .. arg=\"value with \\\"nested \\\\\\\"quotes\\\\\\\" inside\\\"\"\nContent with complex quoting.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "complex");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "arg").unwrap().1.content, "value with \"nested \"quotes\" inside\"");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content with complex quoting.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn blog_post_structure() {
            // Test a realistic blog post with headers, content, links, and footnotes.
            let input = ".article :blog-post-123\n.# Modern Web Development\nThis article discusses modern web development practices.\n\n..section :introduction\nWeb development has evolved significantly over the past decade. \nVisit ((MDN Web Docs|https://developer.mozilla.org)) for comprehensive documentation.\n\n..section :best-practices\nHere are some key practices [1]:\n- Use semantic HTML\n- Implement responsive design\n- Optimize for performance\n\n*1 Based on industry standards and experience.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "blog-post-123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Modern Web Development");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This article discusses modern web development practices.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "introduction");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Web development has evolved significantly over the past decade. ");
                    assert_eq!(lines[1], "Visit ((MDN Web Docs|https://developer.mozilla.org)) for comprehensive documentation.");
                    assert_eq!(lines[2], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "best-practices");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 6);
                    assert_eq!(lines[0], "Here are some key practices [1]:");
                    assert_eq!(lines[1], "- Use semantic HTML");
                    assert_eq!(lines[2], "- Implement responsive design");
                    assert_eq!(lines[3], "- Optimize for performance");
                    assert_eq!(lines[4], "");
                    assert_eq!(lines[5], "*1 Based on industry standards and experience.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn api_documentation_structure() {
            // Test API documentation with code blocks and nested parameters.
            let input = ".api-doc :user-endpoint\n.# User Management API\n\n..endpoint .. method=\"POST\" path=\"/api/users\" :create-user\nCreate a new user account.\n\n...request .. content-type=\"application/json\"\n{\n  \"username\": \"john_doe\",\n  \"email\": \"john@example.com\"\n}\n\n...response .. status=\"201\" type=\"success\"\n{\n  \"id\": 12345,\n  \"username\": \"john_doe\",\n  \"created_at\": \"2023-01-01T00:00:00Z\"\n}";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 14, "Expected 14 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "api-doc");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "user-endpoint");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "User Management API");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "endpoint");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "create-user");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "method").unwrap().1.content, "POST");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "path").unwrap().1.content, "/api/users");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Create a new user account.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "request");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "content-type").unwrap().1.content, "application/json");
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 5);
                    assert_eq!(lines[0], "{");
                    assert_eq!(lines[1], "  \"username\": \"john_doe\",");
                    assert_eq!(lines[2], "  \"email\": \"john@example.com\"");
                    assert_eq!(lines[3], "}");
                    assert_eq!(lines[4], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "response");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "status").unwrap().1.content, "201");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "success");
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 5);
                    assert_eq!(lines[0], "{");
                    assert_eq!(lines[1], "  \"id\": 12345,");
                    assert_eq!(lines[2], "  \"username\": \"john_doe\",");
                    assert_eq!(lines[3], "  \"created_at\": \"2023-01-01T00:00:00Z\"");
                    assert_eq!(lines[4], "}");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
        }

        #[test]
        fn configuration_file_structure() {
            // Test complex configuration with nested structures and various data types.
            let input = ".config :app-settings\n..database .. engine=\"postgresql\" host=\"localhost\" port=5432\n...connection .. pool-size=10 timeout=30\n...credentials .. user=\"app_user\" password=\"secure_pass\"\n\n..cache .. type=\"redis\" enabled=true\n...redis .. host=\"127.0.0.1\" port=6379 db=0\n\n..logging .. level=\"info\" format=\"json\"\n...handlers .. console=true file=true syslog=false";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 18, "Expected 18 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "config");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "app-settings");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "database");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "engine").unwrap().1.content, "postgresql");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "host").unwrap().1.content, "localhost");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "port").unwrap().1.content, "5432");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "connection");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "pool-size").unwrap().1.content, "10");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "timeout").unwrap().1.content, "30");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "credentials");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "user").unwrap().1.content, "app_user");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "password").unwrap().1.content, "secure_pass");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "cache");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "redis");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "redis");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "host").unwrap().1.content, "127.0.0.1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "port").unwrap().1.content, "6379");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "db").unwrap().1.content, "0");
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "logging");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "level").unwrap().1.content, "info");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "format").unwrap().1.content, "json");
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "handlers");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "console").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "file").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "syslog").unwrap().1.content, "false");
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
        }

        #[test]
        fn multi_language_content() {
            // Test document with multiple languages and Unicode scripts.
            let input = ".document :multilingual\n.# Welcome - 欢迎 - مرحبا - स्वागत\n\n..section .. lang=\"en\" :english\nHello World! Visit ((Example|https://example.com)) for more information.\n\n..section .. lang=\"zh\" :chinese\n你好世界！这是中文内容。包含一些((链接|https://example.cn))。\n\n..section .. lang=\"ar\" :arabic\nمرحبا بالعالم! هذا محتوى باللغة العربية.\n\n..section .. lang=\"hi\" :hindi\nनमस्ते दुनिया! यह हिंदी सामग्री है।";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 17, "Expected 17 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "multilingual");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Welcome - 欢迎 - مرحبا - स्वागत");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "english");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "en");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Hello World! Visit ((Example|https://example.com)) for more information.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "chinese");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "zh");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "你好世界！这是中文内容。包含一些((链接|https://example.cn))。");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "arabic");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "ar");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "مرحبا بالعالم! هذا محتوى باللغة العربية.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "hindi");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "hi");
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            match &events[14] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "नमस्ते दुनिया! यह हिंदी सामग्री है।");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
        }

        #[test]
        fn complex_form_definition() {
            // Test form with all argument types and validation rules.
            let input = ".form .. method=\"POST\" action=\"/submit\" enctype=\"multipart/form-data\" :contact-form\n..fieldset User Information :user-info\n...input .. type=\"text\" name=\"username\" required=true placeholder=\"Enter username\" maxlength=50\n...input .. type=\"email\" name=\"email\" required=true validation=\"email\"\n...textarea .. name=\"message\" rows=5 cols=40 placeholder=\"Your message here\"\n\n..fieldset Preferences :preferences  \n...select .. name=\"country\" required=true\n....option .. value=\"us\" selected=true United States\n....option .. value=\"ca\" Canada\n....option .. value=\"uk\" United Kingdom\n\n...input .. type=\"checkbox\" name=\"newsletter\" value=\"yes\" Subscribe to newsletter";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 24, "Expected 24 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "form");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "contact-form");
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "method").unwrap().1.content, "POST");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "/submit");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enctype").unwrap().1.content, "multipart/form-data");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "fieldset");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "user-info");
                    assert_eq!(meta_line.inline_text.content, "User Information");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "input");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 5);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "text");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "username");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "placeholder").unwrap().1.content, "Enter username");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "maxlength").unwrap().1.content, "50");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "input");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 4);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "email");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "email");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "validation").unwrap().1.content, "email");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "textarea");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 4);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "message");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "rows").unwrap().1.content, "5");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "cols").unwrap().1.content, "40");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "placeholder").unwrap().1.content, "Your message here");
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "fieldset");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.inline_text.content, "Preferences");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "select");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "country");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            match &events[12] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "option");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "United");
                    assert_eq!(meta_line.arguments.args[1].content, "States");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "us");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "selected").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "option");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "Canada");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "ca");
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            match &events[16] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "option");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, "United");
                    assert_eq!(meta_line.arguments.args[1].content, "Kingdom");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "uk");
                }
                _ => panic!("Expected BlockStarted at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            match &events[17] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 17, got {:?}", events[17]),
            }
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            assert!(matches!(&events[19], Event::BlockFinished));
            
            // Event 20
            match &events[20] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "input");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Subscribe");
                    assert_eq!(meta_line.arguments.args[1].content, "to");
                    assert_eq!(meta_line.arguments.args[2].content, "newsletter");
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "checkbox");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "newsletter");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "yes");
                }
                _ => panic!("Expected BlockStarted at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            assert!(matches!(&events[21], Event::BlockFinished));
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
        }

        #[test]
        fn rich_text_document() {
            // Test rich text with inline formatting and complex links.
            let input = ".document :rich-text\n.# Advanced Typography\n\n..paragraph\nThis paragraph contains ((emphasis|em)) and ((strong text|strong)) formatting.\nYou can also include ((code snippets|code)) and ((mathematical expressions|math)).\n\n..paragraph \nFor more information, see ((Section 5.2|#section-5-2)) or visit the ((official documentation|https://docs.example.com/advanced#typography)) online.\n\n..paragraph\nComplex links with parameters: ((Submit Form|action://submit .. method=\"POST\" class=\"btn-primary\")).";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 14, "Expected 14 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "rich-text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Advanced Typography");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "This paragraph contains ((emphasis|em)) and ((strong text|strong)) formatting.");
                    assert_eq!(lines[1], "You can also include ((code snippets|code)) and ((mathematical expressions|math)).");
                    assert_eq!(lines[2], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "For more information, see ((Section 5.2|#section-5-2)) or visit the ((official documentation|https://docs.example.com/advanced#typography)) online.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Complex links with parameters: ((Submit Form|action://submit .. method=\"POST\" class=\"btn-primary\")).");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
        }

        #[test]
        fn hierarchical_menu_structure() {
            // Test complex menu with IDs, parameters, and nested items.
            let input = ".navigation :main-menu\n..menu-group File :file-menu\n...menu-item .. action=\"new\" shortcut=\"Ctrl+N\" :new-file New Document\n...menu-item .. action=\"open\" shortcut=\"Ctrl+O\" :open-file Open Document\n...separator\n...menu-item .. action=\"save\" shortcut=\"Ctrl+S\" :save-file Save Document\n\n..menu-group Edit :edit-menu\n...menu-item .. action=\"undo\" shortcut=\"Ctrl+Z\" :undo Undo\n...menu-item .. action=\"redo\" shortcut=\"Ctrl+Y\" :redo Redo\n...separator\n...menu-item .. action=\"cut\" shortcut=\"Ctrl+X\" :cut Cut\n...menu-item .. action=\"copy\" shortcut=\"Ctrl+C\" :copy Copy";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 25, "Expected 25 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "navigation");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "main-menu");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-group");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "file-menu");
                    assert_eq!(meta_line.inline_text.content, "File");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, ":new-file");
                    assert_eq!(meta_line.arguments.args[1].content, "New");
                    assert_eq!(meta_line.arguments.args[2].content, "Document");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "new");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+N");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, ":open-file");
                    assert_eq!(meta_line.arguments.args[1].content, "Open");
                    assert_eq!(meta_line.arguments.args[2].content, "Document");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "open");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+O");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "separator");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, ":save-file");
                    assert_eq!(meta_line.arguments.args[1].content, "Save");
                    assert_eq!(meta_line.arguments.args[2].content, "Document");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "save");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+S");
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            match &events[12] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-group");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "edit-menu");
                    assert_eq!(meta_line.inline_text.content, "Edit");
                }
                _ => panic!("Expected BlockStarted at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, ":undo");
                    assert_eq!(meta_line.arguments.args[1].content, "Undo");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "undo");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+Z");
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, ":redo");
                    assert_eq!(meta_line.arguments.args[1].content, "Redo");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "redo");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+Y");
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            match &events[17] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "separator");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 17, got {:?}", events[17]),
            }
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            match &events[19] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, ":cut");
                    assert_eq!(meta_line.arguments.args[1].content, "Cut");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "cut");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+X");
                }
                _ => panic!("Expected BlockStarted at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            assert!(matches!(&events[20], Event::BlockFinished));
            
            // Event 21
            match &events[21] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "menu-item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 2);
                    assert_eq!(meta_line.arguments.args[0].content, ":copy");
                    assert_eq!(meta_line.arguments.args[1].content, "Copy");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "action").unwrap().1.content, "copy");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "shortcut").unwrap().1.content, "Ctrl+C");
                }
                _ => panic!("Expected BlockStarted at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            assert!(matches!(&events[24], Event::BlockFinished));
        }

        #[test]
        fn data_visualization_markup() {
            // Test data visualization with complex attributes and nested data.
            let input = ".visualization .. type=\"chart\" engine=\"d3\" :sales-chart\n..chart .. chart-type=\"bar\" width=800 height=600\n...title Sales Data Q1 2023\n...axis .. type=\"x\" label=\"Months\"\n...axis .. type=\"y\" label=\"Revenue ($)\"\n\n..dataset :q1-sales\n...data-point .. month=\"Jan\" revenue=125000 :jan-data\n...data-point .. month=\"Feb\" revenue=145000 :feb-data  \n...data-point .. month=\"Mar\" revenue=155000 :mar-data\n\n..styling .. theme=\"professional\" colors=\"blue,green,orange\"\n...legend .. position=\"top-right\" show=true";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 24, "Expected 24 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "visualization");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "sales-chart");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "chart");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "engine").unwrap().1.content, "d3");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "chart");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "chart-type").unwrap().1.content, "bar");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "width").unwrap().1.content, "800");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "height").unwrap().1.content, "600");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.inline_text.content, "Sales Data Q1 2023");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "axis");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "x");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "label").unwrap().1.content, "Months");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "axis");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "y");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "label").unwrap().1.content, "Revenue ($)");
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "dataset");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "q1-sales");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "data-point");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "jan-data");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "month").unwrap().1.content, "Jan");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "revenue").unwrap().1.content, "125000");
                }
                _ => panic!("Expected BlockStarted at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "data-point");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "feb-data");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "month").unwrap().1.content, "Feb");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "revenue").unwrap().1.content, "145000");
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "data-point");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "mar-data");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "month").unwrap().1.content, "Mar");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "revenue").unwrap().1.content, "155000");
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            match &events[16] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            match &events[19] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "styling");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "theme").unwrap().1.content, "professional");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "colors").unwrap().1.content, "blue,green,orange");
                }
                _ => panic!("Expected BlockStarted at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            match &events[20] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "legend");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "position").unwrap().1.content, "top-right");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "show").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            assert!(matches!(&events[21], Event::BlockFinished));
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
        }

        #[test]
        fn mixed_content_types_integration() {
            // Test document combining various content types in realistic scenario.
            let input = ".specification :technical-spec\n.# Product Requirements Document\n\n..overview :project-overview\nThis document outlines the technical specifications for the new web application.\nSee ((Architecture Document|docs/architecture.md)) for system design details.\n\n..requirements :functional-reqs\n...requirement .. priority=\"high\" category=\"authentication\" :auth-req\nUsers must be able to log in using email and password.\n\n...requirement .. priority=\"medium\" category=\"ui\" :ui-req  \nInterface should support both light and dark themes.\n\n..technical-details :tech-stack\n...database .. type=\"postgresql\" version=\"14+\" host=\"db.example.com\"\n...api .. framework=\"fastapi\" version=\"0.68+\" language=\"python\"\n...frontend .. framework=\"react\" version=\"18+\" bundler=\"vite\"\n\n..appendix :references\n*1 See ((OWASP Guidelines|https://owasp.org)) for security standards.\n*2 Refer to ((API Documentation|/api/docs)) for endpoint details.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 28, "Expected 28 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "specification");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "technical-spec");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Product Requirements Document");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "overview");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "project-overview");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "This document outlines the technical specifications for the new web application.");
                    assert_eq!(lines[1], "See ((Architecture Document|docs/architecture.md)) for system design details.");
                    assert_eq!(lines[2], "");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "requirements");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "functional-reqs");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "requirement");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "auth-req");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "priority").unwrap().1.content, "high");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "authentication");
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Users must be able to log in using email and password.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
            
            // Event 11
            match &events[11] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "requirement");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "ui-req");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "priority").unwrap().1.content, "medium");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "ui");
                }
                _ => panic!("Expected BlockStarted at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            match &events[12] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Interface should support both light and dark themes.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "technical-details");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "tech-stack");
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            match &events[16] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "database");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "postgresql");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "version").unwrap().1.content, "14+");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "host").unwrap().1.content, "db.example.com");
                }
                _ => panic!("Expected BlockStarted at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "api");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "framework").unwrap().1.content, "fastapi");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "version").unwrap().1.content, "0.68+");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "python");
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            assert!(matches!(&events[19], Event::BlockFinished));
            
            // Event 20
            match &events[20] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "frontend");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "framework").unwrap().1.content, "react");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "version").unwrap().1.content, "18+");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "bundler").unwrap().1.content, "vite");
                }
                _ => panic!("Expected BlockStarted at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            match &events[21] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            match &events[24] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "appendix");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 24, got {:?}", events[24]),
            }
            
            // Event 25
            match &events[25] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "*1 See ((OWASP Guidelines|https://owasp.org)) for security standards.");
                    assert_eq!(lines[1], "*2 Refer to ((API Documentation|/api/docs)) for endpoint details.");
                    // Checking 2 links
                    assert_eq!(footnotes.len(), 2);
                    assert_eq!(footnotes[0].marker, 1);
                    assert_eq!(footnotes[0].link, "See ((OWASP Guidelines|https://owasp.org)) for security standards.");
                    assert_eq!(footnotes[1].marker, 2);
                    assert_eq!(footnotes[1].link, "Refer to ((API Documentation|/api/docs)) for endpoint details.");
                }
                _ => panic!("Expected TextFinished at index 25, got {:?}", events[25]),
            }
            
            // Event 26
            assert!(matches!(&events[26], Event::BlockFinished));
            
            // Event 27
            assert!(matches!(&events[27], Event::BlockFinished));
        }

        #[test]
        fn cross_referencing_with_ids() {
            // Test document with extensive cross-references between blocks.
            let input = ".tutorial :advanced-tutorial\n.# Advanced Web Development Tutorial\n\n..section :intro\nWelcome to this tutorial. We'll cover ((CSS Grid|#css-grid)) and ((Flexbox|#flexbox)) techniques.\n\n..section .. topic=\"layout\" :css-grid\nCSS Grid Layout\nGrid is perfect for two-dimensional layouts. See ((practical examples|#grid-examples)) below.\n\n..section .. topic=\"layout\" :flexbox  \nFlexbox Layout\nFlexbox excels at one-dimensional layouts. Check out ((flex examples|#flex-examples)) for more.\n\n..examples :grid-examples\nGrid Examples\n...example .. type=\"code\" language=\"css\" :grid-basic\n.container { display: grid; grid-template-columns: 1fr 2fr; }\n\n..examples :flex-examples\nFlexbox Examples  \n...example .. type=\"code\" language=\"css\" :flex-basic\n.container { display: flex; justify-content: center; }\n\n..summary :conclusion\nThis tutorial covered ((grid layout|#css-grid)) and ((flexbox|#flexbox)). \nReview the ((grid examples|#grid-examples)) and ((flex examples|#flex-examples)) as needed.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 33, "Expected 33 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "tutorial");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "advanced-tutorial");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Advanced Web Development Tutorial");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "intro");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Welcome to this tutorial. We'll cover ((CSS Grid|#css-grid)) and ((Flexbox|#flexbox)) techniques.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "css-grid");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "topic").unwrap().1.content, "layout");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "CSS Grid Layout");
                    assert_eq!(lines[1], "Grid is perfect for two-dimensional layouts. See ((practical examples|#grid-examples)) below.");
                    assert_eq!(lines[2], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "flexbox");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "topic").unwrap().1.content, "layout");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Flexbox Layout");
                    assert_eq!(lines[1], "Flexbox excels at one-dimensional layouts. Check out ((flex examples|#flex-examples)) for more.");
                    assert_eq!(lines[2], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "examples");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "grid-examples");
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            match &events[14] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Grid Examples");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "example");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "grid-basic");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "code");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "css");
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            assert!(matches!(&events[18], Event::BlockFinished));
            
            // Event 19
            match &events[19] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "{ display: grid; grid-template-columns: 1fr 2fr; }");
                }
                _ => panic!("Expected BlockStarted at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            match &events[20] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            match &events[21] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "examples");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "flex-examples");
                }
                _ => panic!("Expected BlockStarted at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            match &events[22] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Flexbox Examples  ");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 22, got {:?}", events[22]),
            }
            
            // Event 23
            match &events[23] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "example");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "flex-basic");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "code");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "css");
                }
                _ => panic!("Expected BlockStarted at index 23, got {:?}", events[23]),
            }
            
            // Event 24
            assert!(matches!(&events[24], Event::BlockFinished));
            
            // Event 25
            assert!(matches!(&events[25], Event::BlockFinished));
            
            // Event 26
            assert!(matches!(&events[26], Event::BlockFinished));
            
            // Event 27
            match &events[27] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "{ display: flex; justify-content: center; }");
                }
                _ => panic!("Expected BlockStarted at index 27, got {:?}", events[27]),
            }
            
            // Event 28
            match &events[28] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 28, got {:?}", events[28]),
            }
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "summary");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "conclusion");
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            match &events[30] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This tutorial covered ((grid layout|#css-grid)) and ((flexbox|#flexbox)). ");
                    assert_eq!(lines[1], "Review the ((grid examples|#grid-examples)) and ((flex examples|#flex-examples)) as needed.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 30, got {:?}", events[30]),
            }
            
            // Event 31
            assert!(matches!(&events[31], Event::BlockFinished));
            
            // Event 32
            assert!(matches!(&events[32], Event::BlockFinished));
        }

        #[test]
        fn escaped_content_in_complex_structures() {
            // Test proper escaping within complex nested structures.
            let input = ".documentation :escape-examples\n..code-block .. language=\"javascript\" :js-example\nfunction processData(input) {\n  const pattern = /\\\".*\\\"/g;\n  const escaped = input.replace(/\\\"/g, '\\\\\"');\n  return `Result: \\\"${escaped}\\\"`;\n}\n\n..config-example .. format=\"json\" :json-config\n{\n  \"server\": {\n    \"host\": \"localhost\",\n    \"port\": 8080,\n    \"ssl\": {\n      \"cert\": \"/path/to/\\\"certificate\\\".pem\",\n      \"key\": \"/path/to/\\\"private-key\\\".pem\"\n    }\n  }\n}\n\n..template-example .. type=\"html\" :html-template\n<div class=\"container\">\n  <p>Quote: \\\"Success is 1% inspiration, 99% perspiration.\\\"</p>\n  <code>console.log(\\\"Hello, \\\\\\\"World\\\\\\\"!\\\");</code>\n</div>";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "documentation");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "escape-examples");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "code-block");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "js-example");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "javascript");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 6);
                    assert_eq!(lines[0], "function processData(input) {");
                    assert_eq!(lines[1], "  const pattern = /\\\".*\\\"/g;");
                    assert_eq!(lines[2], "  const escaped = input.replace(/\\\"/g, '\\\\\"');");
                    assert_eq!(lines[3], "  return `Result: \\\"${escaped}\\\"`;");
                    assert_eq!(lines[4], "}");
                    assert_eq!(lines[5], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "config-example");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "json-config");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "format").unwrap().1.content, "json");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 11);
                    assert_eq!(lines[0], "{");
                    assert_eq!(lines[1], "  \"server\": {");
                    assert_eq!(lines[2], "    \"host\": \"localhost\",");
                    assert_eq!(lines[3], "    \"port\": 8080,");
                    assert_eq!(lines[4], "    \"ssl\": {");
                    assert_eq!(lines[5], "      \"cert\": \"/path/to/\\\"certificate\\\".pem\",");
                    assert_eq!(lines[6], "      \"key\": \"/path/to/\\\"private-key\\\".pem\"");
                    assert_eq!(lines[7], "    }");
                    assert_eq!(lines[8], "  }");
                    assert_eq!(lines[9], "}");
                    assert_eq!(lines[10], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "template-example");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "html-template");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "html");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 4);
                    assert_eq!(lines[0], "<div class=\"container\">");
                    assert_eq!(lines[1], "  <p>Quote: \\\"Success is 1% inspiration, 99% perspiration.\\\"</p>");
                    assert_eq!(lines[2], "  <code>console.log(\\\"Hello, \\\\\\\"World\\\\\\\"!\\\");</code>");
                    assert_eq!(lines[3], "</div>");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn large_document_performance() {
            // Test large document with many blocks for performance validation.
            let input = ".large-document :performance-test\n.# Performance Test Document\n\n..section :bulk-content\nThis section contains many repetitive blocks to test parsing performance.\n\n...item .. index=1 category=\"test\" Item 1 content\n...item .. index=2 category=\"test\" Item 2 content  \n...item .. index=3 category=\"test\" Item 3 content\n...item .. index=4 category=\"test\" Item 4 content\n...item .. index=5 category=\"test\" Item 5 content\n...item .. index=6 category=\"test\" Item 6 content\n...item .. index=7 category=\"test\" Item 7 content\n...item .. index=8 category=\"test\" Item 8 content\n...item .. index=9 category=\"test\" Item 9 content\n...item .. index=10 category=\"test\" Item 10 content\n\n..section :performance-metrics\nThis document tests parser performance with multiple blocks, various nesting levels, and mixed content types.\nEach item above has parameters and content to ensure comprehensive testing.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 32, "Expected 32 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "large-document");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "performance-test");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Performance Test Document");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "bulk-content");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This section contains many repetitive blocks to test parsing performance.");
                    assert_eq!(lines[1], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "1");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "2");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "2");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "3");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "3");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            match &events[12] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "4");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "4");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "5");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "5");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            match &events[16] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "6");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "6");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "7");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "7");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            assert!(matches!(&events[19], Event::BlockFinished));
            
            // Event 20
            match &events[20] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "8");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "8");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            assert!(matches!(&events[21], Event::BlockFinished));
            
            // Event 22
            match &events[22] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "9");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "9");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 22, got {:?}", events[22]),
            }
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            match &events[24] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "item");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "Item");
                    assert_eq!(meta_line.arguments.args[1].content, "10");
                    assert_eq!(meta_line.arguments.args[2].content, "content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "index").unwrap().1.content, "10");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "category").unwrap().1.content, "test");
                }
                _ => panic!("Expected BlockStarted at index 24, got {:?}", events[24]),
            }
            
            // Event 25
            match &events[25] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 25, got {:?}", events[25]),
            }
            
            // Event 26
            assert!(matches!(&events[26], Event::BlockFinished));
            
            // Event 27
            assert!(matches!(&events[27], Event::BlockFinished));
            
            // Event 28
            match &events[28] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "performance-metrics");
                }
                _ => panic!("Expected BlockStarted at index 28, got {:?}", events[28]),
            }
            
            // Event 29
            match &events[29] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This document tests parser performance with multiple blocks, various nesting levels, and mixed content types.");
                    assert_eq!(lines[1], "Each item above has parameters and content to ensure comprehensive testing.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            assert!(matches!(&events[30], Event::BlockFinished));
            
            // Event 31
            assert!(matches!(&events[31], Event::BlockFinished));
        }

        #[test]
        fn non_adjacent_text_lines() {
            // Test non-adjacent text lines that remain separate.
            let input = ".container\nFirst text block.\n..nested\nNested content.\nSecond text block.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "First text block.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "nested");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Nested content.");
                    assert_eq!(lines[1], "Second text block.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn url_links() {
            // Test basic URL links in text content.
            let input = ".paragraph\nVisit ((http://example.com)) for more info.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Visit ((http://example.com)) for more info.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn named_links() {
            // Test links with display names.
            let input = ".paragraph\nCheck out ((Example Site|http://example.com)) here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Check out ((Example Site|http://example.com)) here.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn id_reference_links() {
            // Test links to other blocks by ID.
            let input = ".paragraph\nSee the ((:section-id)) for details.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "See the ((:section-id)) for details.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn footnote_links() {
            // Test footnote reference links.
            let input = ".paragraph\nThis needs a reference ((#)).";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This needs a reference ((#)).");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn links_with_arguments() {
            // Test links that contain arguments.
            let input = ".paragraph\nClick ((button .. type=\"submit\" class=\"primary\")) here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click ((button .. type=\"submit\" class=\"primary\")) here.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_links_per_line() {
            // Test multiple links in one line.
            let input = ".paragraph\nGo to ((http://site1.com)) or ((http://site2.com)) now.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Go to ((http://site1.com)) or ((http://site2.com)) now.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn nested_parentheses_in_links() {
            // Test links with nested parentheses.
            let input = ".paragraph\nCheck ((text with )) inside)) for info.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Check ((text with )) inside)) for info.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quoted_content_in_links() {
            // Test links with quoted content.
            let input = ".paragraph\nSee ((\"quoted content\")) here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "See ((\"quoted content\")) here.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_links() {
            // Test links with escaped quotes.
            let input = ".paragraph\nClick ((text \"escaped\")) button.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click ((text \"escaped\")) button.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unclosed_links() {
            // Test handling of unclosed links.
            let input = ".paragraph\nThis has ((unclosed link text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This has ((unclosed link text.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn footnote_marker() {
            // Test footnote marker syntax.
            let input = ".paragraph\nReference text here.\n*1 http://example.com";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Reference text here.");
                    assert_eq!(lines[1], "*1 http://example.com");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_footnotes() {
            // Test multiple footnote markers.
            let input = ".paragraph\nText with references.\n*1 http://site1.com\n*2 http://site2.com\n*3 http://site3.com";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 4);
                    assert_eq!(lines[0], "Text with references.");
                    assert_eq!(lines[1], "*1 http://site1.com");
                    assert_eq!(lines[2], "*2 http://site2.com");
                    assert_eq!(lines[3], "*3 http://site3.com");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn footnote_with_spaces() {
            // Test footnote with spacing variations.
            let input = ".paragraph\nReference here.\n*1    http://example.com";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Reference here.");
                    assert_eq!(lines[1], "*1    http://example.com");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn invalid_footnotes() {
            // Test invalid footnote syntax.
            let input = ".paragraph\nInvalid references.\n* text without number\n*1text without space";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Invalid references.");
                    assert_eq!(lines[1], "* text without number");
                    assert_eq!(lines[2], "*1text without space");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn unclosed_quotes_at_end_of_line() {
            // Test handling of unclosed quotes.
            let input = ".paragraph\nText with \"unclosed quote";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \"unclosed quote");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn mismatched_quote_types() {
            // Test handling of mismatched quote types.
            let input = ".paragraph\nText with \"double quote and single'";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \"double quote and single'");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_quote_levels() {
            // Test nested quotes handling.
            let input = ".paragraph\nText with \"outer \"inner\" outer\" quotes.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \"outer \"inner\" outer\" quotes.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_text() {
            // Test escaped quotes in text content.
            let input = ".paragraph\nText with \\\" escaped quote.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \\\" escaped quote.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_backslashes() {
            // Test escaped backslashes in text.
            let input = ".paragraph\nText with \\\\ escaped backslash.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \\\\ escaped backslash.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn quotes_in_block_type_context() {
            // Test quotes in different contexts - block type.
            let input = ".\"quoted type\" \"inline text\" .. \"arg\" key=\"value\"\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "quoted type");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "inline text");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "arg");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_quoted_strings() {
            // Test escape sequences in quoted strings.
            let input = ".component .. title=\"Text with \\\" escaped quote\"\nComponent content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "component");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "title").unwrap().1.content, "Text with \" escaped quote");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn escaped_quotes_in_unquoted_context() {
            // Test escaped quotes treated literally in unquoted context.
            let input = ".component .. title=text\\\"with\\\"quotes\nComponent content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "component");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "title").unwrap().1.content, "text\\with\\quotes");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Component content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn double_escape_sequences() {
            // Test double escape sequences.
            let input = ".paragraph\nText with \\\\\\\\\" double escaped.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \\\\\\\\\" double escaped.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn invalid_escape_sequences() {
            // Test invalid escape sequences kept as-is.
            let input = ".paragraph\nText with \\n newline and \\t tab.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with \\n newline and \\t tab.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn zero_width_characters() {
            // Test zero-width Unicode characters.
            let input = ".paragraph\nText​with​zero​width​spaces.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text​with​zero​width​spaces.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn right_to_left_text() {
            // Test right-to-left text support.
            let input = ".paragraph\nالعربية עברית text mixed.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "العربية עברית text mixed.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn emoji_with_modifiers() {
            // Test emoji with skin tone modifiers.
            let input = ".paragraph\nEmoji with modifiers: 👋🏻👋🏿🤝🏽";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Emoji with modifiers: 👋🏻👋🏿🤝🏽");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn combining_characters() {
            // Test Unicode combining characters.
            let input = ".paragraph\nCombined: é ñ å characters.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Combined: é ñ å characters.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn control_characters() {
            // Test control characters in text.
            let input = ".paragraph\nText with control chars.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text with control chars.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn meta_line_with_single_dot() {
            // Test basic meta-line detection with single dot.
            let input = ".div\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn meta_line_with_double_dots() {
            // Test meta-line detection with double dots for level 2.
            let input = ".outer\n..inner\nInner content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 5, "Expected 5 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "inner");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Inner content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
        }

        #[test]
        fn meta_line_with_triple_dots() {
            // Test meta-line detection with triple dots for level 3.
            let input = ".level1\n..level2\n...level3\nDeep content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 7, "Expected 7 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Deep content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
        }

        #[test]
        fn line_without_leading_dot() {
            // Test that lines without leading dots are treated as text.
            let input = ".paragraph\nThis is text without a leading dot.\nMore text content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This is text without a leading dot.");
                    assert_eq!(lines[1], "More text content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn empty_line_handling() {
            // Test handling of empty lines in text content.
            let input = ".paragraph\nFirst line.\n\nSecond line after empty.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "First line.");
                    assert_eq!(lines[1], "");
                    assert_eq!(lines[2], "Second line after empty.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn whitespace_only_line() {
            // Test handling of lines with only whitespace.
            let input = ".paragraph\nBefore whitespace.\n   \nAfter whitespace.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "Before whitespace.");
                    assert_eq!(lines[1], "   ");
                    assert_eq!(lines[2], "After whitespace.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn line_with_whitespace_before_dot() {
            // Test that lines with whitespace before dot are treated as text.
            let input = ".paragraph\n  .not-a-meta-line\nText content here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "  .not-a-meta-line");
                    assert_eq!(lines[1], "Text content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn line_with_dot_in_middle() {
            // Test that lines with dots not at start are treated as text.
            let input = ".paragraph\nThis has a . dot in the middle.\nAnd this.has.multiple.dots.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This has a . dot in the middle.");
                    assert_eq!(lines[1], "And this.has.multiple.dots.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn just_a_single_dot_as_empty_type() {
            // Test a single dot creates an empty-type block.
            let input = ".\nText content for empty type.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text content for empty type.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
        }

        #[test]
        fn implicit_close_on_same_level() {
            // Test implicit block closing when same level block starts.
            let input = ".first\nFirst content.\n.second\nSecond content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "first");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "First content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "second");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Second content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn implicit_close_on_lower_level() {
            // Test implicit block closing when lower level block starts.
            let input = ".outer\n..inner\nInner content.\n.new-outer\nNew outer content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "inner");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Inner content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "new-outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "New outer content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn self_closing_heading_block() {
            // Test self-closing blocks using hash syntax.
            let input = ".# Main Title\n.paragraph\nFollowing content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 5, "Expected 5 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Main Title");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Following content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
        }

        #[test]
        fn implicit_text_block() {
            // Test text content without preceding meta-line.
            let input = "This is implicit text content.\nMore implicit text.\n.explicit\nExplicit block content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This is implicit text content.");
                    assert_eq!(lines[1], "More implicit text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "explicit");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Explicit block content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn multiple_dot_levels_mixed() {
            // Test mixed nesting levels that skip intermediate levels.
            let input = ".level1\n...level3\nLevel 3 content.\n..level2\nLevel 2 content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 3 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn arbitrary_deep_nesting() {
            // Test deep nesting with many dot levels.
            let input = ".l1\n..l2\n...l3\n....l4\n.....l5\nDeep content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l4");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l5");
                    assert_eq!(meta_line.level, 5);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Deep content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn root_level_implicit_block() {
            // Test implicit root level behavior with text.
            let input = "Root level text content.\n.explicit\nExplicit block content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Root level text content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "explicit");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Explicit block content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn single_nesting_pattern() {
            // Test basic parent-child nesting relationship.
            let input = ".parent\nParent content.\n..child\nChild content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Parent content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn deep_nesting_sequential_levels() {
            // Test sequential nesting through multiple levels.
            let input = ".level1\n..level2\n...level3\n....level4\n.....level5\n......level6\nContent at level 6.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 13, "Expected 13 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level4");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level5");
                    assert_eq!(meta_line.level, 5);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level6");
                    assert_eq!(meta_line.level, 6);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content at level 6.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
        }

        #[test]
        fn reasonable_deep_nesting() {
            // Test reasonable deep nesting (6 levels).
            let input = ".l1\n..l2\n...l3\n....l4\n.....l5\n......l6\nDeep content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 13, "Expected 13 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l4");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l5");
                    assert_eq!(meta_line.level, 5);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "l6");
                    assert_eq!(meta_line.level, 6);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Deep content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
        }

        #[test]
        fn mixed_nesting_with_level_skips() {
            // Test nesting that skips intermediate levels.
            let input = ".level1\n....level4\nLevel 4 content.\n..level2\nLevel 2 content.\n.......level7\nLevel 7 content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level4");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 4 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level7");
                    assert_eq!(meta_line.level, 7);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 7 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn nested_blocks_with_text_between_levels() {
            // Test text content between different nesting levels.
            let input = ".container\nContainer text.\n..section\nSection text.\nMore container text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Container text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Section text.");
                    assert_eq!(lines[1], "More container text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn nested_blocks_with_empty_parents() {
            // Test nested blocks where parent has no content.
            let input = ".empty-parent\n..child1\nChild 1 content.\n..child2\nChild 2 content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "empty-parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 1 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn reverse_nesting_pattern() {
            // Test nesting from deep to shallow levels.
            let input = ".....deep\nDeep content.\n...medium\nMedium content.\n.shallow\nShallow content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 9, "Expected 9 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "deep");
                    assert_eq!(meta_line.level, 5);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Deep content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "medium");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Medium content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "shallow");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Shallow content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
        }

        #[test]
        fn complex_nesting_patterns() {
            // Test complex mixed nesting with various patterns.
            let input = ".root\n..branch1\n...leaf1\n....deep-leaf\nBranch 1 deep content.\n..branch2\nBranch 2 content.\n...leaf2\nBranch 2 leaf content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 15, "Expected 15 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "root");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf1");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "deep-leaf");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Branch 1 deep content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Branch 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf2");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Branch 2 leaf content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
        }

        #[test]
        fn nested_self_closing_blocks() {
            // Test self-closing blocks at different nesting levels.
            let input = ".container\n..# Section Title\n...paragraph\nSection content.\n..# Another Section";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 9, "Expected 9 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.inline_text.content, "Section Title");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Section content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.inline_text.content, "Another Section");
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
        }

        #[test]
        fn meta_line_with_trailing_whitespace() {
            // Test meta-lines with whitespace after the type.
            let input = ".div   \nContent after whitespace.\n..nested    \nNested content with whitespace.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content after whitespace.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "nested");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Nested content with whitespace.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn meta_line_edge_case_parsing() {
            // Test edge cases in meta-line recognition.
            let input = ".\n..\n...type\nEdge case content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 7, "Expected 7 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Edge case content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
        }

        #[test]
        fn block_level_consistency() {
            // Test consistent level tracking across complex structures.
            let input = ".a\n..b\n...c\n..d\n.e\n..f\nContent at various levels.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 13, "Expected 13 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "a");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "b");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "c");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "d");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "e");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "f");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content at various levels.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
        }

        #[test]
        fn nesting_with_inline_text_and_parameters() {
            // Test nested blocks with meta-line features.
            let input = ".container Main container .. class=\"wrapper\"\n..section Section title .. id=\"main\" :section-1\nSection content here.\n...subsection Subsection title .. role=\"content\"\nSubsection content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Main container ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "wrapper");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "section-1");
                    assert_eq!(meta_line.inline_text.content, "Section title ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "id").unwrap().1.content, "main");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Section content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "subsection");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.inline_text.content, "Subsection title ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "role").unwrap().1.content, "content");
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Subsection content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn siblings_at_same_nesting_level() {
            // Test multiple blocks at the same nesting level.
            let input = ".parent\n..child1\nChild 1 content.\n..child2\nChild 2 content.\n..child3\nChild 3 content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 1 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child3");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 3 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn heading_with_type_suffix() {
            // Test a heading block with a type suffix after the hash.
            let input = ".# chapter";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "chapter");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn basic_self_closing_heading() {
            // Test a basic self-closing heading block with no content.
            let input = ".#";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn self_closing_heading_with_inline_text() {
            // Test a self-closing heading block with inline text.
            let input = ".# Some heading text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Some heading text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn nested_heading_blocks() {
            // Test a heading block nested within another block.
            let input = ".container\n..# subsection";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.inline_text.content, "subsection");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn heading_with_following_text_content() {
            // Test a heading block followed by text content.
            let input = ".# heading\nSome text content after heading.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "heading");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some text content after heading.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn heading_with_parameters() {
            // Test a heading block with parameters.
            let input = ".# chapter .. param=value";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "chapter ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "param").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_unicode_and_emoji() {
            // Test a block type containing Unicode characters and emoji.
            let input = ".émojis👨‍👩‍👧‍👦";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "émojis👨‍👩‍👧‍👦");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_emoji_only() {
            // Test a block type consisting only of emoji characters.
            let input = ".👨‍👩‍👧‍👦";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "👨‍👩‍👧‍👦");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_japanese_characters() {
            // Test a block type containing Japanese characters.
            let input = ".日本語";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "日本語");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_mixed_unicode() {
            // Test a block type with mixed Unicode, Japanese, and emoji characters.
            let input = ".test日本語emoji👨‍👩‍👧‍👦";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "test日本語emoji👨‍👩‍👧‍👦");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_unusual_characters() {
            // Test a block type with unusual character combinations.
            let input = ".type_with_underscores";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type_with_underscores");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_type_with_numbers_and_symbols() {
            // Test a block type containing numbers and symbols.
            let input = ".type123_$symbol";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "type123_$symbol");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn unicode_block_type_with_parameters() {
            // Test a Unicode block type with parameters.
            let input = ".émojis .. param";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "émojis");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "param");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn quoted_unicode_block_type() {
            // Test a quoted block type containing Unicode characters.
            let input = ".\"日本語 type\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "日本語 type");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn empty_heading_with_parameters() {
            // Test an empty heading block with parameters.
            let input = ".# .. id=value";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "id").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_no_inline_text() {
            // Test a block with no inline text content.
            let input = ".div";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_unquoted_inline_text() {
            // Test a block with simple unquoted inline text.
            let input = ".div some text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "some text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_empty_inline_text_before_parameters() {
            // Test a block with empty inline text followed by parameters.
            let input = ".div .. params";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_whitespace_only_inline_text() {
            // Test a block with whitespace-only inline text before parameters.
            let input = ".div    .. params";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "   ");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_quoted_inline_text() {
            // Test a block with quoted inline text.
            let input = ".div \"quoted text\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "quoted text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn inline_text_with_quotes_inside() {
            // Test inline text containing quote characters.
            let input = ".div text with \"quotes\" inside";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text with \"quotes\" inside");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn inline_text_quoted_from_start() {
            // Test inline text that starts with a quote but doesn't close.
            let input = ".div \"text from start";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "\"text from start");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn inline_text_with_escaped_quotes() {
            // Test inline text with escaped quote characters.
            let input = ".div \"text \\\"escaped\\\"\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text \"escaped\"");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn inline_text_with_unicode_and_emoji() {
            // Test inline text containing Unicode characters and emoji.
            let input = ".div 日本語 👨‍👩‍👧‍👦";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "日本語 👨‍👩‍👧‍👦");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn inline_text_with_dots_triggers_parameters() {
            // Test inline text containing dots that triggers parameter parsing.
            let input = ".div text with .. dots";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text with ");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "dots");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_inline_text_and_no_parameters() {
            // Test a block with inline text but no parameter separator.
            let input = ".div text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_parameters_only() {
            // Test a block with only parameters and no inline text.
            let input = ".div .. params";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn parameter_separator_inside_quotes() {
            // Test a block where the parameter separator appears inside quoted inline text.
            let input = ".div \"text .. with dots\" .. params";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "text .. with dots");
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "params");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn quoted_positional_arguments() {
            // Test a block with quoted positional arguments containing spaces.
            let input = ".div .. \"arg with spaces\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "arg with spaces");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn mixed_quoted_and_unquoted_arguments() {
            // Test a block with a mixture of quoted and unquoted positional arguments.
            let input = ".div .. arg1 \"arg 2\" arg3";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 3);
                    assert_eq!(meta_line.arguments.args[0].content, "arg1");
                    assert_eq!(meta_line.arguments.args[1].content, "arg 2");
                    assert_eq!(meta_line.arguments.args[2].content, "arg3");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn empty_quoted_positional_argument() {
            // Test a block with an empty string as a positional argument.
            let input = ".div .. \"\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.args.len(), 1);
                    assert_eq!(meta_line.arguments.args[0].content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn argument_with_equals_but_no_value() {
            // Test a block with an argument that has equals but no value (becomes keyword).
            let input = ".div .. arg=";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "arg").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn keyword_argument_with_empty_value() {
            // Test a block with a keyword argument that has an empty quoted value.
            let input = ".div .. key=\"\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn basic_keyword_argument() {
            // Test a block with a simple keyword argument.
            let input = ".div .. key=value";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "key").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn block_with_simple_id() {
            // Test a block with a simple ID assignment.
            let input = ".div :my-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_placement_with_inline_text() {
            // Test a block with both an ID and inline text.
            let input = ".div inline text :my-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.inline_text.content, "inline text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_placement_with_parameters() {
            // Test a block with both an ID and parameters.
            let input = ".div .. param=value :my-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "param").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_with_inline_text_and_parameters() {
            // Test a block with ID, inline text, and parameters.
            let input = ".div inline text .. param=value :my-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.inline_text.content, "inline text ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "param").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn multiple_ids_in_line() {
            // Test a block with multiple ID syntax elements (only last one used).
            let input = ".div :first-id inline text :second-id";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "second-id");
                    assert_eq!(meta_line.inline_text.content, ":first-id inline text");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_with_multiple_colons() {
            // Test an ID containing multiple colon separators.
            let input = ".div :namespace:sub:item";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "namespace:sub:item");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_containing_numbers() {
            // Test an ID containing numeric characters.
            let input = ".div :item-123";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "item-123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_containing_special_characters() {
            // Test an ID containing underscores and dashes.
            let input = ".div :item_special-chars";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "item_special-chars");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn lone_colon_syntax() {
            // Test a lone colon that doesn't form a valid ID.
            let input = ".div :";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, ":");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn id_with_unicode_characters() {
            // Test an ID containing Unicode characters.
            let input = ".div :café-résumé";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "café-résumé");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn mixed_unicode_id() {
            // Test an ID containing mixed Unicode, Latin, and numeric characters.
            let input = ".div :item日本語-123";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 2, "Expected 2 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "item日本語-123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            assert!(matches!(&events[1], Event::BlockFinished));
        }

        #[test]
        fn text_with_empty_lines() {
            // Test text content containing empty lines.
            let input = ".div\nFirst line of text.\n\nSecond line after empty line.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "First line of text.");
                    assert_eq!(lines[1], "");
                    assert_eq!(lines[2], "Second line after empty line.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn text_content_with_indentation() {
            // Test text content with various levels of indentation.
            let input = ".div\n    Indented text line.\n        More indented text.\n    Back to first indent.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "    Indented text line.");
                    assert_eq!(lines[1], "        More indented text.");
                    assert_eq!(lines[2], "    Back to first indent.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn text_with_trailing_whitespace() {
            // Test text content with trailing spaces and tabs.
            let input = ".div\nText with trailing spaces.   \nMore text with tabs.	";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "div");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Text with trailing spaces.   ");
                    assert_eq!(lines[1], "More text with tabs.	");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn parent_with_mixed_text_and_child_blocks() {
            // Test a parent block containing both text content and child blocks.
            let input = ".parent\nParent text content.\n..child\nChild content.\nMore parent text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Parent text content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Child content.");
                    assert_eq!(lines[1], "More parent text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn non_adjacent_text_blocks() {
            // Test text blocks separated by nested block elements.
            let input = ".parent\nFirst text block.\n..child\nChild content.\nSecond text block.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "First text block.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Child content.");
                    assert_eq!(lines[1], "Second text block.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn sequential_sibling_blocks() {
            // Test multiple sibling blocks at the same nesting level.
            let input = ".parent\n..child1\nFirst child.\n..child2\nSecond child.\n..child3\nThird child.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "First child.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Second child.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child3");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Third child.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }

        #[test]
        fn deep_nesting_with_text_at_each_level() {
            // Test multiple levels of nesting with text content at each level.
            let input = ".level1\nLevel 1 text.\n..level2\nLevel 2 text.\n...level3\nLevel 3 text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 9, "Expected 9 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level1");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 1 text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 2 text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level3");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Level 3 text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
        }

        #[test]
        fn parent_block_with_only_child_content() {
            // Test a parent block that contains only child blocks, no direct text.
            let input = ".parent\n..child1\nChild 1 content.\n..child2\nChild 2 content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 8, "Expected 8 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parent");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 1 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child 2 content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
        }

        #[test]
        fn block_with_all_content_types_combined() {
            // Test a block combining inline text, parameters, ID, text content, and child blocks.
            let input = ".container inline text .. param=value :my-id\nText content here.\n..child\nChild content.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "container");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "my-id");
                    assert_eq!(meta_line.inline_text.content, "inline text ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "param").unwrap().1.content, "value");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Text content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "child");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Child content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn complex_nested_structure() {
            // Test a complex tree structure with multiple branches and levels.
            let input = ".root\nRoot text.\n..branch1\nBranch 1 text.\n...leaf1\nLeaf content.\n..branch2\n...leaf2\nAnother leaf.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 14, "Expected 14 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "root");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Root text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch1");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Branch 1 text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf1");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Leaf content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "branch2");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "leaf2");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Another leaf.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
        }

        #[test]
        fn link_with_complex_url_parameters() {
            // Test a link containing URL parameters and special characters.
            let input = ".text\nVisit ((https://example.com/path?param=value&other=123)) for details.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Visit ((https://example.com/path?param=value&other=123)) for details.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn link_with_special_characters_in_display_name() {
            // Test a named link with quotes and symbols in the display text.
            let input = ".text\nClick ((Name with \"quotes\" & symbols|https://example.com)) here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Click ((Name with \"quotes\" & symbols|https://example.com)) here.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn link_url_with_nested_parentheses() {
            // Test a link URL containing parentheses within the URL.
            let input = ".text\nAPI call ((https://example.com/func(param))) available.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "API call ((https://example.com/func(param))) available.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn link_with_pipe_characters() {
            // Test a link containing pipe characters.
            let input = ".text\nExample ((Link|with|pipes|https://example.com)) text.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Example ((Link|with|pipes|https://example.com)) text.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_link_types_in_one_line() {
            // Test combining URL, named, and ID reference links in one text.
            let input = ".text\nCheck ((https://docs.com)), see ((Main Page|https://main.com)), and go to ((:intro)) section.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Check ((https://docs.com)), see ((Main Page|https://main.com)), and go to ((:intro)) section.");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn links_at_text_boundaries() {
            // Test links positioned at the beginning and end of text.
            let input = ".text\n((Start link)) in middle text ((end link)).";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "((Start link)) in middle text ((end link)).");
                    // Checking 1 links
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn basic_footnote_reference() {
            // Test basic footnote syntax with reference and definition.
            let input = ".text\nThis is important text [1].\n*1 See footnote for details.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "This is important text [1].");
                    assert_eq!(lines[1], "*1 See footnote for details.");
                    let _ = links;
                    assert_eq!(footnotes.len(), 1);
                    assert_eq!(footnotes[0].marker, 1);
                    assert_eq!(footnotes[0].link, "See footnote for details.");
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn multiple_footnotes_with_sequential_numbering() {
            // Test multiple footnotes with sequential numeric markers.
            let input = ".text\nFirst [1], second [2], and third [3] items.\n*1 First footnote\n*2 Second footnote\n*3 Third footnote";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 4);
                    assert_eq!(lines[0], "First [1], second [2], and third [3] items.");
                    assert_eq!(lines[1], "*1 First footnote");
                    assert_eq!(lines[2], "*2 Second footnote");
                    assert_eq!(lines[3], "*3 Third footnote");
                    let _ = links;
                    assert_eq!(footnotes.len(), 3);
                    assert_eq!(footnotes[0].marker, 1);
                    assert_eq!(footnotes[0].link, "First footnote");
                    assert_eq!(footnotes[1].marker, 2);
                    assert_eq!(footnotes[1].link, "Second footnote");
                    assert_eq!(footnotes[2].marker, 3);
                    assert_eq!(footnotes[2].link, "Third footnote");
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn footnote_containing_links() {
            // Test a footnote definition that contains link syntax.
            let input = ".text\nComplex reference [1] here.\n*1 See ((https://example.com)) for more info.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 2);
                    assert_eq!(lines[0], "Complex reference [1] here.");
                    assert_eq!(lines[1], "*1 See ((https://example.com)) for more info.");
                    // Checking 1 links
                    assert_eq!(footnotes.len(), 1);
                    assert_eq!(footnotes[0].marker, 1);
                    assert_eq!(footnotes[0].link, "See ((https://example.com)) for more info.");
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn invalid_footnote_syntax() {
            // Test text with invalid footnote references and malformed markers.
            let input = ".text\nInvalid reference [invalid] and malformed *invalid marker.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "text");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Invalid reference [invalid] and malformed *invalid marker.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
        }

        #[test]
        fn blog_post_with_complex_nesting() {
            // Test a realistic blog post structure with deep nesting and metadata.
            let input = ".article :blog-post-123\n..title .. class=\"main-heading\"\nBuilding Modern Web Applications\n..meta .. published=\"2024-01-15\" author=\"Jane Smith\"\nPublished January 15, 2024 by Jane Smith\n..abstract\nThis article explores the latest trends in web development, including modern frameworks, performance optimization, and user experience design patterns.\n..section :introduction\n...h2\nIntroduction\n...p\nModern web development has evolved significantly over the past decade. This article will cover the essential concepts and tools needed to build performant, accessible web applications.\n..section :frameworks\n...h2\nFramework Comparison\n...subsection :react\n....h3\nReact Ecosystem\n....p\nReact continues to dominate the frontend landscape with its component-based architecture and extensive ecosystem.\n....code-block .. language=\"javascript\"\nconst App = () => {\n  return <div>Hello World</div>;\n};\n...subsection :vue\n....h3\nVue.js Features\n....p\nVue.js offers a gentler learning curve while maintaining powerful features for complex applications.\n..conclusion\nIn conclusion, the choice of framework depends on project requirements, team expertise, and long-term maintenance considerations.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 46, "Expected 46 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "blog-post-123");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "class").unwrap().1.content, "main-heading");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Building Modern Web Applications");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "meta");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "published").unwrap().1.content, "2024-01-15");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "author").unwrap().1.content, "Jane Smith");
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Published January 15, 2024 by Jane Smith");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "abstract");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This article explores the latest trends in web development, including modern frameworks, performance optimization, and user experience design patterns.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "introduction");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "h2");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            match &events[12] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Introduction");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "p");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            match &events[15] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Modern web development has evolved significantly over the past decade. This article will cover the essential concepts and tools needed to build performant, accessible web applications.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "frameworks");
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            match &events[19] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "h2");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            match &events[20] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Framework Comparison");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            assert!(matches!(&events[21], Event::BlockFinished));
            
            // Event 22
            match &events[22] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "subsection");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "react");
                }
                _ => panic!("Expected BlockStarted at index 22, got {:?}", events[22]),
            }
            
            // Event 23
            match &events[23] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "h3");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 23, got {:?}", events[23]),
            }
            
            // Event 24
            match &events[24] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "React Ecosystem");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 24, got {:?}", events[24]),
            }
            
            // Event 25
            assert!(matches!(&events[25], Event::BlockFinished));
            
            // Event 26
            match &events[26] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "p");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 26, got {:?}", events[26]),
            }
            
            // Event 27
            match &events[27] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "React continues to dominate the frontend landscape with its component-based architecture and extensive ecosystem.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 27, got {:?}", events[27]),
            }
            
            // Event 28
            assert!(matches!(&events[28], Event::BlockFinished));
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "code-block");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "language").unwrap().1.content, "javascript");
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            match &events[30] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 3);
                    assert_eq!(lines[0], "const App = () => {");
                    assert_eq!(lines[1], "  return <div>Hello World</div>;");
                    assert_eq!(lines[2], "};");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 30, got {:?}", events[30]),
            }
            
            // Event 31
            assert!(matches!(&events[31], Event::BlockFinished));
            
            // Event 32
            assert!(matches!(&events[32], Event::BlockFinished));
            
            // Event 33
            match &events[33] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "subsection");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.id.value, "vue");
                }
                _ => panic!("Expected BlockStarted at index 33, got {:?}", events[33]),
            }
            
            // Event 34
            match &events[34] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "h3");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 34, got {:?}", events[34]),
            }
            
            // Event 35
            match &events[35] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Vue.js Features");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 35, got {:?}", events[35]),
            }
            
            // Event 36
            assert!(matches!(&events[36], Event::BlockFinished));
            
            // Event 37
            match &events[37] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "p");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 37, got {:?}", events[37]),
            }
            
            // Event 38
            match &events[38] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Vue.js offers a gentler learning curve while maintaining powerful features for complex applications.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 38, got {:?}", events[38]),
            }
            
            // Event 39
            assert!(matches!(&events[39], Event::BlockFinished));
            
            // Event 40
            assert!(matches!(&events[40], Event::BlockFinished));
            
            // Event 41
            assert!(matches!(&events[41], Event::BlockFinished));
            
            // Event 42
            match &events[42] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "conclusion");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 42, got {:?}", events[42]),
            }
            
            // Event 43
            match &events[43] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "In conclusion, the choice of framework depends on project requirements, team expertise, and long-term maintenance considerations.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 43, got {:?}", events[43]),
            }
            
            // Event 44
            assert!(matches!(&events[44], Event::BlockFinished));
            
            // Event 45
            assert!(matches!(&events[45], Event::BlockFinished));
        }

        #[test]
        fn api_documentation_with_nested_structures() {
            // Test API documentation with complex nested parameter and response structures.
            let input = ".api-documentation .. version=\"2.1\" format=\"openapi\"\n..endpoint .. method=\"POST\" path=\"/api/users\" :create-user\n...description\nCreate a new user account with the provided information.\n...request\n....headers\n.....header .. name=\"Content-Type\" required=true\napplication/json\n.....header .. name=\"Authorization\" required=false\nBearer token (optional for public registration)\n....body .. schema=\"UserCreateRequest\"\n.....field .. name=\"email\" type=\"string\" required=true\nUser's email address\n.....field .. name=\"password\" type=\"string\" required=true minLength=8\nUser's password (minimum 8 characters)\n.....field .. name=\"profile\" type=\"object\" required=false\n.......field .. name=\"firstName\" type=\"string\"\n.......field .. name=\"lastName\" type=\"string\"\n...response .. status=201\n....body .. schema=\"UserResponse\"\n.....field .. name=\"id\" type=\"string\"\nUnique user identifier\n.....field .. name=\"email\" type=\"string\"\n.....field .. name=\"createdAt\" type=\"timestamp\"\n...response .. status=400\n....body .. schema=\"ErrorResponse\"\n.....field .. name=\"error\" type=\"string\"\n.....field .. name=\"details\" type=\"array\"\n..endpoint .. method=\"GET\" path=\"/api/users/{id}\" :get-user\n...parameter .. name=\"id\" location=\"path\" type=\"string\" required=true\nUser identifier";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 55, "Expected 55 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "api-documentation");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "version").unwrap().1.content, "2.1");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "format").unwrap().1.content, "openapi");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "endpoint");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "create-user");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "method").unwrap().1.content, "POST");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "path").unwrap().1.content, "/api/users");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "description");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Create a new user account with the provided information.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "request");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "headers");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "header");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "Content-Type");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "application/json");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "header");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "Authorization");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "false");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Bearer token (optional for public registration)");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            match &events[14] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "body");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "schema").unwrap().1.content, "UserCreateRequest");
                }
                _ => panic!("Expected BlockStarted at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "email");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            match &events[16] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "User's email address");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 4);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "password");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "minLength").unwrap().1.content, "8");
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            match &events[19] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "User's password (minimum 8 characters)");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            assert!(matches!(&events[20], Event::BlockFinished));
            
            // Event 21
            match &events[21] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "profile");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "object");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "false");
                }
                _ => panic!("Expected BlockStarted at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            match &events[22] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 7);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "firstName");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                }
                _ => panic!("Expected BlockStarted at index 22, got {:?}", events[22]),
            }
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            match &events[24] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 7);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "lastName");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                }
                _ => panic!("Expected BlockStarted at index 24, got {:?}", events[24]),
            }
            
            // Event 25
            assert!(matches!(&events[25], Event::BlockFinished));
            
            // Event 26
            assert!(matches!(&events[26], Event::BlockFinished));
            
            // Event 27
            assert!(matches!(&events[27], Event::BlockFinished));
            
            // Event 28
            assert!(matches!(&events[28], Event::BlockFinished));
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "response");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "status").unwrap().1.content, "201");
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            match &events[30] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "body");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "schema").unwrap().1.content, "UserResponse");
                }
                _ => panic!("Expected BlockStarted at index 30, got {:?}", events[30]),
            }
            
            // Event 31
            match &events[31] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "id");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                }
                _ => panic!("Expected BlockStarted at index 31, got {:?}", events[31]),
            }
            
            // Event 32
            match &events[32] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Unique user identifier");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 32, got {:?}", events[32]),
            }
            
            // Event 33
            assert!(matches!(&events[33], Event::BlockFinished));
            
            // Event 34
            match &events[34] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "email");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                }
                _ => panic!("Expected BlockStarted at index 34, got {:?}", events[34]),
            }
            
            // Event 35
            assert!(matches!(&events[35], Event::BlockFinished));
            
            // Event 36
            match &events[36] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "createdAt");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "timestamp");
                }
                _ => panic!("Expected BlockStarted at index 36, got {:?}", events[36]),
            }
            
            // Event 37
            assert!(matches!(&events[37], Event::BlockFinished));
            
            // Event 38
            assert!(matches!(&events[38], Event::BlockFinished));
            
            // Event 39
            assert!(matches!(&events[39], Event::BlockFinished));
            
            // Event 40
            match &events[40] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "response");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "status").unwrap().1.content, "400");
                }
                _ => panic!("Expected BlockStarted at index 40, got {:?}", events[40]),
            }
            
            // Event 41
            match &events[41] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "body");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "schema").unwrap().1.content, "ErrorResponse");
                }
                _ => panic!("Expected BlockStarted at index 41, got {:?}", events[41]),
            }
            
            // Event 42
            match &events[42] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "error");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                }
                _ => panic!("Expected BlockStarted at index 42, got {:?}", events[42]),
            }
            
            // Event 43
            assert!(matches!(&events[43], Event::BlockFinished));
            
            // Event 44
            match &events[44] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "field");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "details");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "array");
                }
                _ => panic!("Expected BlockStarted at index 44, got {:?}", events[44]),
            }
            
            // Event 45
            assert!(matches!(&events[45], Event::BlockFinished));
            
            // Event 46
            assert!(matches!(&events[46], Event::BlockFinished));
            
            // Event 47
            assert!(matches!(&events[47], Event::BlockFinished));
            
            // Event 48
            assert!(matches!(&events[48], Event::BlockFinished));
            
            // Event 49
            match &events[49] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "endpoint");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "get-user");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "method").unwrap().1.content, "GET");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "path").unwrap().1.content, "/api/users/{id}");
                }
                _ => panic!("Expected BlockStarted at index 49, got {:?}", events[49]),
            }
            
            // Event 50
            match &events[50] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "parameter");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 4);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "name").unwrap().1.content, "id");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "location").unwrap().1.content, "path");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "string");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "required").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 50, got {:?}", events[50]),
            }
            
            // Event 51
            match &events[51] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "User identifier");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 51, got {:?}", events[51]),
            }
            
            // Event 52
            assert!(matches!(&events[52], Event::BlockFinished));
            
            // Event 53
            assert!(matches!(&events[53], Event::BlockFinished));
            
            // Event 54
            assert!(matches!(&events[54], Event::BlockFinished));
        }

        #[test]
        fn configuration_file_with_hierarchical_settings() {
            // Test a complex configuration file structure with nested settings and environment variables.
            let input = ".configuration .. env=\"production\" version=\"1.0\"\n..database\n...connection .. driver=\"postgresql\" pool=true\n....host .. value=\"db.example.com\" env=\"DB_HOST\"\n....port .. value=5432 env=\"DB_PORT\"\n....database .. value=\"myapp_prod\" env=\"DB_NAME\"\n....credentials\n.....username .. value=\"app_user\" env=\"DB_USER\"\n.....password .. value=\"***\" env=\"DB_PASSWORD\" encrypted=true\n....pool-settings\n.....min-connections .. value=5\n.....max-connections .. value=20\n.....idle-timeout .. value=30000 unit=\"ms\"\n..cache\n...redis\n....host .. value=\"cache.example.com\" env=\"REDIS_HOST\"\n....port .. value=6379 env=\"REDIS_PORT\"\n....database .. value=0\n....ttl .. value=3600 unit=\"seconds\"\n..logging\n...level .. value=\"info\" env=\"LOG_LEVEL\"\n...destinations\n....console .. enabled=true format=\"json\"\n....file .. enabled=true path=\"/var/log/app.log\" rotation=\"daily\"\n....syslog .. enabled=false facility=\"local0\"\n..features .. experimental=false\n...feature-flags\n....new-ui .. enabled=false percentage=10\n....advanced-search .. enabled=true\n....beta-api .. enabled=false whitelist=\"admin,tester\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 60, "Expected 60 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "configuration");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "production");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "version").unwrap().1.content, "1.0");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "database");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "connection");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "driver").unwrap().1.content, "postgresql");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "pool").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "host");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "db.example.com");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "DB_HOST");
                }
                _ => panic!("Expected BlockStarted at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "port");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "5432");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "DB_PORT");
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "database");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "myapp_prod");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "DB_NAME");
                }
                _ => panic!("Expected BlockStarted at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "credentials");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "username");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "app_user");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "DB_USER");
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            assert!(matches!(&events[11], Event::BlockFinished));
            
            // Event 12
            match &events[12] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "password");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "***");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "DB_PASSWORD");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "encrypted").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 12, got {:?}", events[12]),
            }
            
            // Event 13
            assert!(matches!(&events[13], Event::BlockFinished));
            
            // Event 14
            assert!(matches!(&events[14], Event::BlockFinished));
            
            // Event 15
            match &events[15] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "pool-settings");
                    assert_eq!(meta_line.level, 4);
                }
                _ => panic!("Expected BlockStarted at index 15, got {:?}", events[15]),
            }
            
            // Event 16
            match &events[16] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "min-connections");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "5");
                }
                _ => panic!("Expected BlockStarted at index 16, got {:?}", events[16]),
            }
            
            // Event 17
            assert!(matches!(&events[17], Event::BlockFinished));
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "max-connections");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "20");
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            assert!(matches!(&events[19], Event::BlockFinished));
            
            // Event 20
            match &events[20] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "idle-timeout");
                    assert_eq!(meta_line.level, 5);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "30000");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "unit").unwrap().1.content, "ms");
                }
                _ => panic!("Expected BlockStarted at index 20, got {:?}", events[20]),
            }
            
            // Event 21
            assert!(matches!(&events[21], Event::BlockFinished));
            
            // Event 22
            assert!(matches!(&events[22], Event::BlockFinished));
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            assert!(matches!(&events[24], Event::BlockFinished));
            
            // Event 25
            match &events[25] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "cache");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 25, got {:?}", events[25]),
            }
            
            // Event 26
            match &events[26] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "redis");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 26, got {:?}", events[26]),
            }
            
            // Event 27
            match &events[27] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "host");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "cache.example.com");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "REDIS_HOST");
                }
                _ => panic!("Expected BlockStarted at index 27, got {:?}", events[27]),
            }
            
            // Event 28
            assert!(matches!(&events[28], Event::BlockFinished));
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "port");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "6379");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "REDIS_PORT");
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            assert!(matches!(&events[30], Event::BlockFinished));
            
            // Event 31
            match &events[31] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "database");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "0");
                }
                _ => panic!("Expected BlockStarted at index 31, got {:?}", events[31]),
            }
            
            // Event 32
            assert!(matches!(&events[32], Event::BlockFinished));
            
            // Event 33
            match &events[33] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "ttl");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "3600");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "unit").unwrap().1.content, "seconds");
                }
                _ => panic!("Expected BlockStarted at index 33, got {:?}", events[33]),
            }
            
            // Event 34
            assert!(matches!(&events[34], Event::BlockFinished));
            
            // Event 35
            assert!(matches!(&events[35], Event::BlockFinished));
            
            // Event 36
            assert!(matches!(&events[36], Event::BlockFinished));
            
            // Event 37
            match &events[37] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "logging");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 37, got {:?}", events[37]),
            }
            
            // Event 38
            match &events[38] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "level");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "value").unwrap().1.content, "info");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "env").unwrap().1.content, "LOG_LEVEL");
                }
                _ => panic!("Expected BlockStarted at index 38, got {:?}", events[38]),
            }
            
            // Event 39
            assert!(matches!(&events[39], Event::BlockFinished));
            
            // Event 40
            match &events[40] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "destinations");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 40, got {:?}", events[40]),
            }
            
            // Event 41
            match &events[41] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "console");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "format").unwrap().1.content, "json");
                }
                _ => panic!("Expected BlockStarted at index 41, got {:?}", events[41]),
            }
            
            // Event 42
            assert!(matches!(&events[42], Event::BlockFinished));
            
            // Event 43
            match &events[43] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "file");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 3);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "path").unwrap().1.content, "/var/log/app.log");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "rotation").unwrap().1.content, "daily");
                }
                _ => panic!("Expected BlockStarted at index 43, got {:?}", events[43]),
            }
            
            // Event 44
            assert!(matches!(&events[44], Event::BlockFinished));
            
            // Event 45
            match &events[45] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "syslog");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "false");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "facility").unwrap().1.content, "local0");
                }
                _ => panic!("Expected BlockStarted at index 45, got {:?}", events[45]),
            }
            
            // Event 46
            assert!(matches!(&events[46], Event::BlockFinished));
            
            // Event 47
            assert!(matches!(&events[47], Event::BlockFinished));
            
            // Event 48
            assert!(matches!(&events[48], Event::BlockFinished));
            
            // Event 49
            match &events[49] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "features");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "experimental").unwrap().1.content, "false");
                }
                _ => panic!("Expected BlockStarted at index 49, got {:?}", events[49]),
            }
            
            // Event 50
            match &events[50] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "feature-flags");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 50, got {:?}", events[50]),
            }
            
            // Event 51
            match &events[51] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "new-ui");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "false");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "percentage").unwrap().1.content, "10");
                }
                _ => panic!("Expected BlockStarted at index 51, got {:?}", events[51]),
            }
            
            // Event 52
            assert!(matches!(&events[52], Event::BlockFinished));
            
            // Event 53
            match &events[53] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "advanced-search");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "true");
                }
                _ => panic!("Expected BlockStarted at index 53, got {:?}", events[53]),
            }
            
            // Event 54
            assert!(matches!(&events[54], Event::BlockFinished));
            
            // Event 55
            match &events[55] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "beta-api");
                    assert_eq!(meta_line.level, 4);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "enabled").unwrap().1.content, "false");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "whitelist").unwrap().1.content, "admin,tester");
                }
                _ => panic!("Expected BlockStarted at index 55, got {:?}", events[55]),
            }
            
            // Event 56
            assert!(matches!(&events[56], Event::BlockFinished));
            
            // Event 57
            assert!(matches!(&events[57], Event::BlockFinished));
            
            // Event 58
            assert!(matches!(&events[58], Event::BlockFinished));
            
            // Event 59
            assert!(matches!(&events[59], Event::BlockFinished));
        }

        #[test]
        fn multi_language_content_with_unicode() {
            // Test content in multiple languages with proper Unicode handling.
            let input = ".document .. lang=\"multi\" encoding=\"utf-8\"\n..section .. lang=\"en\" :english-content\n...title\nWelcome to Our International Service\n...content\nThis platform supports multiple languages and international users from around the world.\n..section .. lang=\"es\" :spanish-content\n...title\nBienvenido a Nuestro Servicio Internacional\n...content\nEsta plataforma admite múltiples idiomas y usuarios internacionales de todo el mundo.\n..section .. lang=\"ja\" :japanese-content\n...title\n国際サービスへようこそ\n...content\nこのプラットフォームは、世界中の複数の言語と国際的なユーザーをサポートしています。\n..section .. lang=\"ar\" dir=\"rtl\" :arabic-content\n...title\nمرحباً بكم في خدمتنا الدولية\n...content\nتدعم هذه المنصة لغات متعددة ومستخدمين دوليين من جميع أنحاء العالم.\n..section .. lang=\"zh\" :chinese-content\n...title\n欢迎使用我们的国际服务\n...content\n该平台支持多种语言和来自世界各地的国际用户。\n..section .. lang=\"hi\" :hindi-content\n...title\nहमारी अंतर्राष्ट्रीय सेवा में आपका स्वागत है\n...content\nयह प्लेटफॉर्म दुनिया भर की कई भाषाओं और अंतर्राष्ट्रीय उपयोगकर्ताओं का समर्थन करता है।";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 50, "Expected 50 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "multi");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "encoding").unwrap().1.content, "utf-8");
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "english-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "en");
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Welcome to Our International Service");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This platform supports multiple languages and international users from around the world.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            match &events[9] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "spanish-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "es");
                }
                _ => panic!("Expected BlockStarted at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            match &events[10] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 10, got {:?}", events[10]),
            }
            
            // Event 11
            match &events[11] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Bienvenido a Nuestro Servicio Internacional");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 11, got {:?}", events[11]),
            }
            
            // Event 12
            assert!(matches!(&events[12], Event::BlockFinished));
            
            // Event 13
            match &events[13] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 13, got {:?}", events[13]),
            }
            
            // Event 14
            match &events[14] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Esta plataforma admite múltiples idiomas y usuarios internacionales de todo el mundo.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 14, got {:?}", events[14]),
            }
            
            // Event 15
            assert!(matches!(&events[15], Event::BlockFinished));
            
            // Event 16
            assert!(matches!(&events[16], Event::BlockFinished));
            
            // Event 17
            match &events[17] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "japanese-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "ja");
                }
                _ => panic!("Expected BlockStarted at index 17, got {:?}", events[17]),
            }
            
            // Event 18
            match &events[18] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 18, got {:?}", events[18]),
            }
            
            // Event 19
            match &events[19] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "国際サービスへようこそ");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 19, got {:?}", events[19]),
            }
            
            // Event 20
            assert!(matches!(&events[20], Event::BlockFinished));
            
            // Event 21
            match &events[21] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 21, got {:?}", events[21]),
            }
            
            // Event 22
            match &events[22] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "このプラットフォームは、世界中の複数の言語と国際的なユーザーをサポートしています。");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 22, got {:?}", events[22]),
            }
            
            // Event 23
            assert!(matches!(&events[23], Event::BlockFinished));
            
            // Event 24
            assert!(matches!(&events[24], Event::BlockFinished));
            
            // Event 25
            match &events[25] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "arabic-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "ar");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "dir").unwrap().1.content, "rtl");
                }
                _ => panic!("Expected BlockStarted at index 25, got {:?}", events[25]),
            }
            
            // Event 26
            match &events[26] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 26, got {:?}", events[26]),
            }
            
            // Event 27
            match &events[27] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "مرحباً بكم في خدمتنا الدولية");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 27, got {:?}", events[27]),
            }
            
            // Event 28
            assert!(matches!(&events[28], Event::BlockFinished));
            
            // Event 29
            match &events[29] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 29, got {:?}", events[29]),
            }
            
            // Event 30
            match &events[30] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "تدعم هذه المنصة لغات متعددة ومستخدمين دوليين من جميع أنحاء العالم.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 30, got {:?}", events[30]),
            }
            
            // Event 31
            assert!(matches!(&events[31], Event::BlockFinished));
            
            // Event 32
            assert!(matches!(&events[32], Event::BlockFinished));
            
            // Event 33
            match &events[33] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "chinese-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "zh");
                }
                _ => panic!("Expected BlockStarted at index 33, got {:?}", events[33]),
            }
            
            // Event 34
            match &events[34] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 34, got {:?}", events[34]),
            }
            
            // Event 35
            match &events[35] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "欢迎使用我们的国际服务");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 35, got {:?}", events[35]),
            }
            
            // Event 36
            assert!(matches!(&events[36], Event::BlockFinished));
            
            // Event 37
            match &events[37] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 37, got {:?}", events[37]),
            }
            
            // Event 38
            match &events[38] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "该平台支持多种语言和来自世界各地的国际用户。");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 38, got {:?}", events[38]),
            }
            
            // Event 39
            assert!(matches!(&events[39], Event::BlockFinished));
            
            // Event 40
            assert!(matches!(&events[40], Event::BlockFinished));
            
            // Event 41
            match &events[41] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                    assert_eq!(meta_line.id.value, "hindi-content");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "lang").unwrap().1.content, "hi");
                }
                _ => panic!("Expected BlockStarted at index 41, got {:?}", events[41]),
            }
            
            // Event 42
            match &events[42] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "title");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 42, got {:?}", events[42]),
            }
            
            // Event 43
            match &events[43] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "हमारी अंतर्राष्ट्रीय सेवा में आपका स्वागत है");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 43, got {:?}", events[43]),
            }
            
            // Event 44
            assert!(matches!(&events[44], Event::BlockFinished));
            
            // Event 45
            match &events[45] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 45, got {:?}", events[45]),
            }
            
            // Event 46
            match &events[46] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "यह प्लेटफॉर्म दुनिया भर की कई भाषाओं और अंतर्राष्ट्रीय उपयोगकर्ताओं का समर्थन करता है।");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 46, got {:?}", events[46]),
            }
            
            // Event 47
            assert!(matches!(&events[47], Event::BlockFinished));
            
            // Event 48
            assert!(matches!(&events[48], Event::BlockFinished));
            
            // Event 49
            assert!(matches!(&events[49], Event::BlockFinished));
        }

        #[test]
        fn simple_context_line() {
            // Test a basic context line at level 1.
            let input = ".block\n./metadata\nSome content";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "block");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some content");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn context_line_with_inline_text() {
            // Test a context line with inline text content.
            let input = ".block\n./author John Doe\nSome content";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "block");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Some content");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn nested_context_line() {
            // Test a context line at level 2 inside a nested block.
            let input = ".outer\n..inner\n../version 1.0\nContent here";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "inner");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn multiple_context_lines() {
            // Test multiple context lines in sequence.
            let input = ".document\n./author Alice\n./date 2024-01-15\n./version 1.0\nDocument content here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 6, "Expected 6 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            
            // Event 2
            
            // Event 3
            
            // Event 4
            match &events[4] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Document content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            assert!(matches!(&events[5], Event::BlockFinished));
        }

        #[test]
        fn context_line_with_id() {
            // Test a context line with an explicit ID.
            let input = ".block\n./meta :my-metadata\nContent";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 4, "Expected 4 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "block");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            
            // Event 2
            match &events[2] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            assert!(matches!(&events[3], Event::BlockFinished));
        }

        #[test]
        fn context_line_does_not_affect_block_structure() {
            // Test that context lines don't close or open blocks.
            let input = ".outer\n..inner\n../contextinfo\nMore nested content\n..another\nContent in another";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 9, "Expected 9 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "outer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "inner");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "More nested content");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "another");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content in another");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
        }
    }

    mod void_elements {
        use super::*;

        #[test]
        fn basic_void_element() {
            // Test a simple void element with no additional content.
            let input = ".hr:";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_inline_text() {
            // Test a void element that has inline text.
            let input = ".img: A beautiful sunset";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "img");
                    assert_eq!(meta_line.inline_text.content, "A beautiful sunset");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_arguments() {
            // Test a void element with keyword arguments after the double-dot separator.
            let input = ".img: alt text here .. src=\"photo.jpg\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "img");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "alt text here ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 1);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "src").unwrap().1.content, "photo.jpg");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_id() {
            // Test a void element with an ID specified.
            let input = ".timestamp: 2024-01-15 :ts1";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "timestamp");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "ts1");
                    assert_eq!(meta_line.inline_text.content, "2024-01-15");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_arguments_and_id() {
            // Test a void element with both arguments and an ID.
            let input = ".img: alt text .. src=\"sunset.jpg\" alt=\"Sunset\" :fig1";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "img");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.id.value, "fig1");
                    assert_eq!(meta_line.inline_text.content, "alt text ");
                    assert_eq!(meta_line.arguments.kwargs.len(), 2);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "src").unwrap().1.content, "sunset.jpg");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "alt").unwrap().1.content, "Sunset");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn nested_void_element() {
            // Test a void element at a deeper nesting level.
            let input = "..nested-void:";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "nested-void");
                    assert_eq!(meta_line.level, 2);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn deeply_nested_void_element() {
            // Test a void element at level 3.
            let input = "...deep-void: with text";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "deep-void");
                    assert_eq!(meta_line.level, 3);
                    assert_eq!(meta_line.inline_text.content, "with text");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_quoted_type_name() {
            // Test a void element where the type name contains spaces.
            let input = ".\"page break\":";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "page break");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_quoted_type_and_inline_text() {
            // Test a void element with quoted type name and inline text.
            let input = ".\"section divider\": ~~~";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "section divider");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "~~~");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_does_not_affect_block_nesting() {
            // Test that a void element inside a block doesn't close or modify the parent block structure.
            let input = ".document\nThis is inside the document.\n..hr:\nStill inside the document.\n./";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 5, "Expected 5 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "This is inside the document.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 2);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Still inside the document.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
        }

        #[test]
        fn multiple_void_elements_in_sequence() {
            // Test multiple void elements one after another.
            let input = ".br:\n.hr:\n.br:";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 3, "Expected 3 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "br");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "br");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 2, got {:?}", events[2]),
            }
        }

        #[test]
        fn void_element_between_nested_blocks() {
            // Test void elements interspersed with regular nested blocks.
            let input = ".article\nOpening paragraph.\n..section\nSection content.\n..hr:\n..another-section\nMore content.\n./";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 10, "Expected 10 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "article");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Opening paragraph.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Section content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 2);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "another-section");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            match &events[7] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "More content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
        }

        #[test]
        fn void_heading_using_syntax() {
            // Test that self-closing headings can also be void.
            let input = ".#: Introduction";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "#");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.inline_text.content, "Introduction");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_with_empty_inline_text() {
            // Test a void element with no inline text.
            let input = ".marker:";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "marker");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn void_element_inside_deeply_nested_structure() {
            // Test void elements at various levels within a nested structure.
            let input = ".document\n..chapter\n...section\n....hr:\n...paragraph\nContent here.";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 10, "Expected 10 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "document");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "chapter");
                    assert_eq!(meta_line.level, 2);
                }
                _ => panic!("Expected BlockStarted at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            match &events[2] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "section");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 2, got {:?}", events[2]),
            }
            
            // Event 3
            match &events[3] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 4);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            assert!(matches!(&events[4], Event::BlockFinished));
            
            // Event 5
            match &events[5] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "paragraph");
                    assert_eq!(meta_line.level, 3);
                }
                _ => panic!("Expected BlockStarted at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            match &events[6] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Content here.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 6, got {:?}", events[6]),
            }
            
            // Event 7
            assert!(matches!(&events[7], Event::BlockFinished));
            
            // Event 8
            assert!(matches!(&events[8], Event::BlockFinished));
            
            // Event 9
            assert!(matches!(&events[9], Event::BlockFinished));
        }

        #[test]
        fn void_element_with_complex_arguments() {
            // Test a void element with multiple keyword arguments including quoted values.
            let input = ".embed: .. type=\"video\" src=\"https://example.com/video.mp4\" autoplay=\"true\" width=\"640\" height=\"480\"";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 1, "Expected 1 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "embed");
                    assert_eq!(meta_line.level, 1);
                    assert_eq!(meta_line.arguments.kwargs.len(), 5);
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "type").unwrap().1.content, "video");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "src").unwrap().1.content, "https://example.com/video.mp4");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "autoplay").unwrap().1.content, "true");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "width").unwrap().1.content, "640");
                    assert_eq!(meta_line.arguments.kwargs.iter().find(|(k, _)| k.content == "height").unwrap().1.content, "480");
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 0, got {:?}", events[0]),
            }
        }

        #[test]
        fn mixed_void_and_regular_blocks_at_same_level() {
            // Test alternating between void and regular blocks at the same nesting level.
            let input = ".intro\nWelcome text.\n./\n.hr:\n.content\nMain content.\n./\n.hr:\n.footer\nFooter text.\n./";

            // Parse input and collect events
            let emitter = WasotFileEmitter::from_string(input.to_string());
            let receiver = emitter.subscribe();
            
            std::thread::spawn(move || {
                emitter.run();
            });
            
            let mut events = Vec::new();
            for event in receiver {
                events.push(event);
            }

            // Verify events
            assert_eq!(events.len(), 11, "Expected 11 events, got {}", events.len());
            
            // Event 0
            match &events[0] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "intro");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 0, got {:?}", events[0]),
            }
            
            // Event 1
            match &events[1] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Welcome text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 1, got {:?}", events[1]),
            }
            
            // Event 2
            assert!(matches!(&events[2], Event::BlockFinished));
            
            // Event 3
            match &events[3] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 3, got {:?}", events[3]),
            }
            
            // Event 4
            match &events[4] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "content");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 4, got {:?}", events[4]),
            }
            
            // Event 5
            match &events[5] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Main content.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 5, got {:?}", events[5]),
            }
            
            // Event 6
            assert!(matches!(&events[6], Event::BlockFinished));
            
            // Event 7
            match &events[7] {
                Event::VoidElement { meta_line } => {
                    assert_eq!(meta_line.type_name, "hr");
                    assert_eq!(meta_line.level, 1);
                    assert!(meta_line.is_void, "VoidElement should have is_void=true");
                }
                _ => panic!("Expected VoidElement at index 7, got {:?}", events[7]),
            }
            
            // Event 8
            match &events[8] {
                Event::BlockStarted { meta_line } => {
                    assert_eq!(meta_line.type_name, "footer");
                    assert_eq!(meta_line.level, 1);
                }
                _ => panic!("Expected BlockStarted at index 8, got {:?}", events[8]),
            }
            
            // Event 9
            match &events[9] {
                Event::TextFinished { lines, links, footnotes } => {
                    assert_eq!(lines.len(), 1);
                    assert_eq!(lines[0], "Footer text.");
                    let _ = links;
                    let _ = footnotes;
                }
                _ => panic!("Expected TextFinished at index 9, got {:?}", events[9]),
            }
            
            // Event 10
            assert!(matches!(&events[10], Event::BlockFinished));
        }
    }
}