fn split_samples<'a, I>(parser: I) -> Vec<Event<'a>>
where
    I: Iterator<Item = Event<'a>>,
{
    let mut res: Vec<Event> = vec![];
    let mut count = 0;

    let mut pending: Vec<Event> = vec![];

    // make pending into one block
    let resolve = |pending: &mut Vec<Event<'a>>, res: &mut Vec<Event<'a>>, count: &mut i32| {
        if pending.is_empty() {
            return;
        }
        *count += 1;
        res.push(Event::Html(format!(
            "<div class=\"sample\"> <h5 class=\"underline\">サンプル{}</h5> <div class=\"paragraph\"> ",
            count).into()));
        res.append(pending); // pending.len() == 0
        res.push(Event::Html("</div></div>\n".into()));
    };

    let mut parser = parser.peekable();
    while let Some(e) = parser.peek() {
        match e {
            Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(lang))) => match lang.as_ref() {
                "sample-input" => {
                    resolve(&mut pending, &mut res, &mut count);
                    let before = Event::Html("<h6>入力</h6><pre>\n".into());
                    let after = Event::Html("</pre>".into());
                    let mut g = get_subtree(&mut parser);
                    pending.append(
                        &mut iter::once(before)
                            .chain(g.drain(1..g.len() - 1))
                            .chain(iter::once(after))
                            .collect(),
                    );
                }
                "sample-output" => {
                    let before = Event::Html("<h6>出力</h6><pre>".into());
                    let after = Event::Html("</pre>".into());
                    let mut g = get_subtree(&mut parser);
                    pending.append(
                        &mut iter::once(before)
                            .chain(g.drain(1..g.len() - 1))
                            .chain(iter::once(after))
                            .collect(),
                    );
                    // pending.append(&mut wrap_subtree(&mut parser, iter::once(before), iter::once(after)));
                }
                _ => {
                    if !pending.is_empty() {
                        pending.push(parser.next().unwrap());
                    } else {
                        res.push(parser.next().unwrap());
                    }
                }
            },
            _ => {
                if !pending.is_empty() {
                    pending.push(parser.next().unwrap());
                } else {
                    res.push(parser.next().unwrap());
                }
            }
        }
    }
    resolve(&mut pending, &mut res, &mut count);

    res
}
/// split sapmles into blocks by 'sample-input' code blocks
split sapmles into blocks by 'sample-input' code blocks
split sapmles into blocks by ' sample - input ' code blocks
fn split_samples<'a, I>(parser: I) -> Vec<Event<'a>>
where
    I: Iterator<Item = Event<'a>>,
{
    let mut res: Vec<Event> = vec![];
    let mut count = 0;
    let mut pending: Vec<Event> = vec![];
    // make pending into one block
    let resolve = |pending: &mut Vec<Event<'a>>, res: &mut Vec<Event<'a>>, count: &mut i32| {
        if pending.is_empty() {
            return;
        }
        *count += 1;
        res.push(Event::Html(format!(
            "<div class=\"sample\"> <h5 class=\"underline\">サンプル{}</h5> <div class=\"paragraph\"> ",
            count).into()));
        res.append(pending); // pending.len() == 0
        res.push(Event::Html("</div></div>\n".into()));
    };
    let mut parser = parser.peekable();
    while let Some(e) = parser.peek() {
        match e {
            Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(lang))) => match lang.as_ref() {
                "sample-input" => {
                    resolve(&mut pending, &mut res, &mut count);
                    let before = Event::Html("<h6>入力</h6><pre>\n".into());
                    let after = Event::Html("</pre>".into());
                    let mut g = get_subtree(&mut parser);
                    pending.append(
                        &mut iter::once(before)
                            .chain(g.drain(1..g.len() - 1))
                            .chain(iter::once(after))
                            .collect(),
                    );
                }
                "sample-output" => {
                    let before = Event::Html("<h6>出力</h6><pre>".into());
                    let after = Event::Html("</pre>".into());
                    let mut g = get_subtree(&mut parser);
                    pending.append(
                        &mut iter::once(before)
                            .chain(g.drain(1..g.len() - 1))
                            .chain(iter::once(after))
                            .collect(),
                    );
                    // pending.append(&mut wrap_subtree(&mut parser, iter::once(before), iter::once(after)));
                }
                _ => {
                    if !pending.is_empty() {
                        pending.push(parser.next().unwrap());
                    } else {
                        res.push(parser.next().unwrap());
                    }
                }
            },
            _ => {
                if !pending.is_empty() {
                    pending.push(parser.next().unwrap());
                } else {
                    res.push(parser.next().unwrap());
                }
            }
        }
    }
    resolve(&mut pending, &mut res, &mut count);
    res
}
fn split_samples < ' a , I > ( parser : I ) -> Vec < Event < ' a > > where I : Iterator < Item = Event < ' a > > , { let mut res : Vec < Event > = vec ! [ ] ; let mut count = 0 ; let mut pending : Vec < Event > = vec ! [ ] ; // make pending into one block let resolve = | pending : & mut Vec < Event < ' a > > , res : & mut Vec < Event < ' a > > , count : & mut i32 | { if pending . is_empty ( ) { return ; } * count += 1 ; res . push ( Event :: Html ( format ! ( " \" \" \" \" ap count ) . into ( ) ) ) ; res . append ( pending ) ; // pending.len() == 0 res . push ( Event :: Html ( " \n " . into ( ) ) ) ; } ; let mut parser = parser . peekable ( ) ; while let Some ( e ) = parser . peek ( ) { match e { Event :: Start ( Tag :: CodeBlock ( CodeBlockKind :: Fenced ( lang ) ) ) => match lang . as_ref ( ) { " " => { resolve ( & mut pending , & mut res , & mut count ) ; let before = Event :: Html ( " in t o ()); let after = Event :: Html ( " " . into ( ) ) ; let mut g = get_subtree ( & mut parser ) ; pending . append ( & mut iter :: once ( before ) . chain ( g . drain ( 1 .. g . len ( ) - 1 ) ) . chain ( iter :: once ( after ) ) . collect ( ) , ) ; } " " => { let before = Event :: Html ( " t o ()); let after = Event :: Html ( " " . into ( ) ) ; let mut g = get_subtree ( & mut parser ) ; pending . append ( & mut iter :: once ( before ) . chain ( g . drain ( 1 .. g . len ( ) - 1 ) ) . chain ( iter :: once ( after ) ) . collect ( ) , ) ; // pending.append(&mut wrap_subtree(&mut parser, iter::once(before), iter::once(after))); } _ => { if ! pending . is_empty ( ) { pending . push ( parser . next ( ) . unwrap ( ) ) ; } else { res . push ( parser . next ( ) . unwrap ( ) ) ; } } } , _ => { if ! pending . is_empty ( ) { pending . push ( parser . next ( ) . unwrap ( ) ) ; } else { res . push ( parser . next ( ) . unwrap ( ) ) ; } } } } resolve ( & mut pending , & mut res , & mut count ) ; res }
split sapmles into blocks by 'sample-input' code blocks
split sapmles into blocks by ' sample - input ' code blocks
parser
I