# flatten the update content to plain text
tree = BeautifulSoup(payload_data["body_html"], "html.parser")
- worklist = tree.contents
+ worklist = list(reversed(tree.contents))
out = [[]]
while worklist:
el = worklist.pop()
out[-1].append(el)
elif el is SPACE:
out[-1].append(el)
- elif el is NEW_LINE or el.name == "br" or el.name == "hr":
+ elif el is NEW_LINE or el.name in ["br", "hr"]:
if out[-1]:
out.append([])
elif el.name in ["em", "strong", "del", "span", "sup", "code", "a", "th", "td"]:
def _parse_from_lines(lines: list[str], curr_count: Optional[int], bot_user: str) -> ParsedUpdate:
command = next(
- filter(None, (_parse_command(l, bot_user) for l in lines)),
+ (cmd for l in lines if (cmd := _parse_command(l, bot_user))),
None
)
if lines:
if parts in partials:
# missing any of last two digits
typo = True
- elif parts in [p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials]:
+ elif any(parts == p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials):
# double paste
typo = True