I have 1 solution but it has the same limitations as the solution that ADW mentioned and that is that it requires 2 rows before the first text block. However, I managed to place all the formulas into 1 cell.
=if(AND(A18="",A16="",A17=""),row(),if((A16="")*(A17=""),textjoin("<break time=""1000ms""/>", 1,indirect("A"&row()&":"&concatenate("A",min(arrayformula(if((B19:B109="")*(B20:B110=""),"",row(B18:B))))))),""))
This is the formula for cell B3, and you would just need to drag it down the column.
On a side note, I think that ADW's solutions are great but there is a slight error in ADW's solution A, you would need to add a -1 in the formula, changing it from:
=indirect("A"&row()&":A"&row(indirect("E"&if(B3="","", min(B4:B)))))
to
=indirect("A"&row()&":A"&row(indirect("E"&if(B3="","", min(B4:B)-1))))
I am only commenting here as i have insufficient reputation to comment to his solution.