Separation of text from headings is required, by inserting a blank line after the last. The text has the following structure:
Заголовок заголовок заголовок Слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово слово.
Signs of the title: begins with a capital letter, does not end with a punctuation mark, has a length of up to 30 characters, the subsequent line also begins with a capital letter.
Accordingly, it is necessary after the line with the title to add a second carriage return. At the moment in the python script there is the following regular expression, which, however, finding the headers, replaces them with an empty string:
текст = re.sub("^[А-Я]{1}.{,30}\n", "\n", текст) ADDITIVE
¡Thanks to @ReinRaus for this proposed solution:
текст = re.sub("^([А-Я]{1}.{,30}\n)", r"\1\n", текст)