Commit a3277117 authored by Richard Berger's avatar Richard Berger
Browse files

Add filter which merges preformatted sections

parent 67d4c076
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -90,3 +90,24 @@ def promote_doc_keywords(content):

def filter_multiple_horizontal_rules(content):
    return re.sub(r"----------[\s\n]+----------", '', content)


def merge_preformatted_sections(content):
    mergable_section_pattern = re.compile(r"\.\. parsed-literal::\n"
                                          r"\n"
                                          r"(?P<listingA>((   [^\n]+\n)|(^\n))+)\n\s*"
                                          r"^\.\. parsed-literal::\n"
                                          r"\n"
                                          r"(?P<listingB>((   [^\n]+\n)|(^\n))+)\n", re.MULTILINE | re.DOTALL)

    m = mergable_section_pattern.search(content)

    while m:
        content = mergable_section_pattern.sub(r".. parsed-literal::\n"
                                            r"\n"
                                            r"\g<listingA>"
                                            r"\g<listingB>"
                                            r"\n", content)
        m = mergable_section_pattern.search(content)

    return content
+1 −0
Original line number Diff line number Diff line
@@ -359,6 +359,7 @@ class Txt2Rst(TxtParser):
        self.document_filters.append(lammps_filters.detect_and_add_command_to_index)
        self.document_filters.append(lammps_filters.filter_multiple_horizontal_rules)
        self.document_filters.append(lammps_filters.promote_doc_keywords)
        self.document_filters.append(lammps_filters.merge_preformatted_sections)

    def is_ignored_textblock_begin(self, line):
        return line.startswith('<!-- HTML_ONLY -->')