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 @@ -192,6 +192,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)


# remove copyable snippet code
def remove_copyable(match):
return ''
Expand All @@ -213,6 +234,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)

Expand Down