private Block generateTree ( List < HeaderBlock > headers , int start , int depth , boolean numbered , String documentReference ) { Block tocBlock = null ; int currentLevel = start - 1 ; Block currentBlock = null ; for ( HeaderBlock headerBlock : headers ) { int headerLevel = headerBlock . getLevel ( ) . getAsInt ( ) ; if ( headerLevel >= start && headerLevel <= depth ) { // Move to next header in toc tree if ( currentLevel < headerLevel ) { while ( currentLevel < headerLevel ) { if ( currentBlock instanceof ListBLock ) { currentBlock = addItemBlock ( currentBlock , null , documentReference ) ; } currentBlock = createChildListBlock ( numbered , currentBlock ) ; ++ currentLevel ; } } else { while ( currentLevel > headerLevel ) { currentBlock = currentBlock . getParent ( ) . getParent ( ) ; -- currentLevel ; } currentBlock = currentBlock . getParent ( ) ; } currentBlock = addItemBlock ( currentBlock , headerBlock , documentReference ) ; } } if ( currentBlock != null ) { tocBlock = currentBlock . getRoot ( ) ; } return tocBlock ; }
Convert headers into list block tree .