the detction of when toc are necessary is leaky. It is not resetting the state correctly so every header thinks it needs a toc.