Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/merge_by_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ def replace_heading(match):
return replace_heading


# remove <StickyHeaderTable> / </StickyHeaderTable> tags for PDF output
sticky_header_table_pattern = re.compile(r'^\s*</?StickyHeaderTable\s*/?>\s*$')

def remove_sticky_header_table(text):
lines = text.split('\n')
result = []
i = 0
while i < len(lines):
if sticky_header_table_pattern.match(lines[i]):
prev_blank = len(result) > 0 and result[-1].strip() == ''
next_blank = i + 1 < len(lines) and lines[i + 1].strip() == ''
if prev_blank and next_blank:
i += 2
else:
i += 1
else:
result.append(lines[i])
i += 1
return '\n'.join(result)

Comment on lines +235 to +236
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

According to PEP 8, top-level function and class definitions should be surrounded by two blank lines. Currently, there is only one blank line between remove_sticky_header_table and remove_copyable.

Suggested change
return '\n'.join(result)
return '\n'.join(result)
References
  1. PEP 8: Surround top-level function and class definitions with two blank lines. (link)


# remove copyable snippet code
def remove_copyable(match):
return ""
Expand All @@ -233,6 +254,7 @@ def remove_copyable(match):
chapter = replace_variables(chapter, variables)
chapter = replace_link_wrap(chapter, name)
chapter = copyable_snippet_pattern.sub(remove_copyable, chapter)
chapter = remove_sticky_header_table(chapter)
chapter = extract_custom_ids_and_clean(chapter)
chapter = replace_custom_id_links(chapter)
# This block is to filter <CustomContent paltform="xxx"> xxx </CustomContent>
Expand Down