pub fn calculate_code_block_token_count<'a, I, E>(events: I) -> Option<usize>
where I: IntoIterator<Item = E>, E: Borrow<Event<'a>>,
Expand description

Return the <seen amount of consecutive fenced code-block tokens> + 1 that occur within a fenced code-block events.

Use this function to obtain the correct value for code_block_token_count field of Options to assure that the enclosing code-blocks remain functional as such.

Returns None if events didn’t include any code-block, or the code-block didn’t contain a nested block. In that case, the correct amount of fenced code-block tokens is DEFAULT_CODE_BLOCK_TOKEN_COUNT.

use pulldown_cmark::Event;
use pulldown_cmark_to_cmark::*;

let events = &[Event::Text("text".into())];
let code_block_token_count = calculate_code_block_token_count(events).unwrap_or(DEFAULT_CODE_BLOCK_TOKEN_COUNT);
let options = Options {
    code_block_token_count,
    ..Default::default()
};
let mut buf = String::new();
cmark_with_options(events.iter(), &mut buf, options);