From: Jann Horn Date: Sun, 1 Sep 2024 21:55:32 +0000 (+0200) Subject: refactor html block printing X-Git-Url: http://git.thejh.net/?a=commitdiff_plain;h=a627e7cfb531474d98e288f2ad7511618d77dc55;p=mehlbrei.git refactor html block printing --- diff --git a/threadview.py b/threadview.py index f52bbef..0de3861 100755 --- a/threadview.py +++ b/threadview.py @@ -367,17 +367,15 @@ with open('/tmp/lkml-out.html', 'wt') as outfile: outfile.write('
\n') for topic_root in all_topic_roots: outfile.write('
\n') - top_post_blocks = list(filter(lambda x: x.start_pos_child < 0, topic_root.blocks.ranges)) - thread_post_blocks = list(filter(lambda x: x.start_pos_child >= 0, topic_root.blocks.ranges)) - if len(top_post_blocks) != 0: - outfile.write('

Top-posted messages (sorry this looks like a mess)

\n') - for block in top_post_blocks: - outfile.write('
\n') - outfile.write('
'+html.escape(block.message.from_hdr, quote=False)+'
\n') - outfile.write('
'+html.escape(block.get_text(), quote=False)+'
\n') - outfile.write('
\n') - outfile.write('

Actual thread

\n') - for block in thread_post_blocks: + printed_top_header = False + printed_threads_header = False + for block in topic_root.blocks.ranges: + if block.start_pos_child < 0 and not printed_top_header: + outfile.write('

Top-posted messages (sorry this section looks like a mess)

\n') + printed_top_header = True + if block.start_pos_child >= 0 and not printed_threads_header: + outfile.write('

Actual thread

\n') + printed_threads_header = True outfile.write('
\n') outfile.write('
'+html.escape(block.message.from_hdr, quote=False)+'
\n') outfile.write('
'+html.escape(block.get_text(), quote=False)+'
\n')