Close parent tags before insertion

In case of insertion inside parent blocks it will be closed before pagebreak code and open after in same order.