Add filter which merges preformatted sections

This commit is contained in:
Richard Berger 2016-09-26 18:47:21 -04:00
parent 67d4c07689
commit a3277117e2
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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 -->')