Optimize to only iterate over rules once. Possible by using a similar structure as the formatting logic. The block rules would parse all instances of themselves in the text and return these. You need to mark what their place was in the document. Then after each rule has been parsed you remove the section from the lines. The same offset handling as in the formatting should be used.
As per the
TODO
inBlockParser
:Optimize to only iterate over rules once. Possible by using a similar structure as the formatting logic. The block rules would parse all instances of themselves in the text and return these. You need to mark what their place was in the document. Then after each rule has been parsed you remove the section from the lines. The same offset handling as in the formatting should be used.