Skip to main content

write_back_verified

Function write_back_verified 

Source
pub fn write_back_verified(
    content: &str,
    blocks: &[FencedCodeBlockInfo],
    write_backs: &[WriteBack],
    extract: impl Fn(&str) -> Vec<FencedCodeBlockInfo>,
) -> (String, Vec<usize>)
Expand description

content with each write-back’s code in place of its block’s code, keeping only the write-backs after which extract still reads the document as the same blocks with exactly the new code; and the indices of the blocks whose write-back was refused.

Whether new code can sit where the old code did depends on more than the block’s containers: code with a line that closes the fence ends the block early, and everything after that line becomes document. A refused block keeps its original code. extract must be the function blocks came from, so an unchanged document reads back as exactly blocks, in document order.

Blocks are expected not to overlap. Write-backs to blocks that do are refused, since replacing one would leave the other’s range pointing at different text.