diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-05-12 10:06:34 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-05-12 10:25:45 +0200 |
commit | 8c33418c97a5bf37819c2344f9750e19b1bf192f (patch) | |
tree | b39351230de65fb355eca95c2d7aa064e52ccf63 /alot/widgets | |
parent | e2b3f678be5e1a9f07b2ba921d759b1813c65115 (diff) |
widgets/thread: factor out quote parsing
Diffstat (limited to 'alot/widgets')
-rw-r--r-- | alot/widgets/thread.py | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 631d6abe..78d974f2 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -191,24 +191,8 @@ class _TextPart(_MIMEPartWidget): attrs_quote = settings.get_quote_theming() fold_context = settings.get('thread_fold_context') - lines = text.splitlines() - - blocks = [] - max_level = 0 - for line in lines: - level = 0 - m = re.match(self._QUOTE_REGEX, line) - if m is not None: - g = m.group(0) - for c in self._QUOTE_CHARS: - level += g.count(c) - - max_level = max(max_level, level) - - if len(blocks) > 0 and blocks[-1][0] == level: - blocks[-1][1].append(line) - else: - blocks.append((level, [line])) + blocks = self._split_quotes(text) + max_level = max((b[0] for b in blocks)) block_wgts = [] for level, lines in blocks: @@ -225,6 +209,28 @@ class _TextPart(_MIMEPartWidget): super().__init__(urwid.Pile(block_wgts)) + def _split_quotes(self, text): + """ + Split the text into blocks of quote levels. + """ + lines = text.splitlines() + + blocks = [] + for line in lines: + level = 0 + m = re.match(self._QUOTE_REGEX, line) + if m is not None: + g = m.group(0) + for c in self._QUOTE_CHARS: + level += g.count(c) + + if len(blocks) > 0 and blocks[-1][0] == level: + blocks[-1][1].append(line) + else: + blocks.append((level, [line])) + + return blocks + @property def foldlevel(self): return self._fold_level |