+ # we need to replace newlines with new layouts
+ start_newline = -1
+ started_text = False
+ for lno in range(0,len(postoptstuff)):
+ if postoptstuff[lno].startswith("\\begin_inset Newline newline"):
+ start_newline = lno
+ elif start_newline != -1:
+ if postoptstuff[lno].startswith("\\end_inset"):
+ # replace that bit, but only if we already have some text
+ # and we're not at the end except for a blank line
+ if started_text and \
+ (lno != len(postoptstuff) - 2 or postoptstuff[-1] != ""):
+ newstuff.extend(['\\end_layout', '\n', '\\begin_layout Plain Layout', '\n'])
+ start_newline = -1
+ started_text = True
+ else:
+ newstuff.extend([postoptstuff[lno]])