diff --git a/src/api/util.py b/src/api/util.py index dabdd22..e87f4f9 100644 --- a/src/api/util.py +++ b/src/api/util.py @@ -57,15 +57,15 @@ def parse_mediawiki_changes(ctx: Context, content: str, embed: DiscordMessage) - edit_diff = ctx.client.content_parser() edit_diff.feed(content) if edit_diff.small_prev_del: - if edit_diff.small_prev_del.replace("~~", "").isspace(): + if edit_diff.small_prev_del.replace("~~", "").replace("__", "").isspace(): edit_diff.small_prev_del = _('__Only whitespace__') else: - edit_diff.small_prev_del = edit_diff.small_prev_del.replace("~~~~", "") + edit_diff.small_prev_del = edit_diff.small_prev_del.replace("~~~~", "").replace("____", "") if edit_diff.small_prev_ins: - if edit_diff.small_prev_ins.replace("**", "").isspace(): + if edit_diff.small_prev_ins.replace("**", "").replace("__", "").isspace(): edit_diff.small_prev_ins = _('__Only whitespace__') else: - edit_diff.small_prev_ins = edit_diff.small_prev_ins.replace("****", "") + edit_diff.small_prev_ins = edit_diff.small_prev_ins.replace("****", "").replace("____", "") logger.debug("Changed content: {}".format(edit_diff.small_prev_ins)) if edit_diff.small_prev_del and not ctx.event == "new": embed.add_field(_("Removed"), "{data}".format(data=edit_diff.small_prev_del), inline=True) diff --git a/src/misc.py b/src/misc.py index 512f33f..f02e8cc 100644 --- a/src/misc.py +++ b/src/misc.py @@ -183,15 +183,18 @@ class ContentParser(HTMLParser): self.last_del = self.last_del + data def handle_endtag(self, tagname): - self.current_tag = "" if tagname == "ins": self.current_tag = "tda" elif tagname == "del": self.current_tag = "tdd" + elif tagname == "td": + self.current_tag = "" elif tagname == "tr": if self.last_ins is not None: self.ins_length += 1 - if self.empty and not self.last_ins.isspace() and "**" not in self.last_ins: + if self.empty and not self.last_ins.isspace(): + if "**" not in self.last_ins: + self.last_ins = self.last_ins.replace("**", "__") self.ins_length += 4 self.last_ins = "**" + self.last_ins + "**" self.small_prev_ins = self.small_prev_ins + "\n" + self.last_ins @@ -200,7 +203,9 @@ class ContentParser(HTMLParser): self.last_ins = None if self.last_del is not None: self.del_length += 1 - if self.empty and not self.last_del.isspace() and "~~" not in self.last_del: + if self.empty and not self.last_del.isspace(): + if "~~" not in self.last_del: + self.last_del = self.last_del.replace("~~", "__") self.del_length += 4 self.last_del = "~~" + self.last_del + "~~" self.small_prev_del = self.small_prev_del + "\n" + self.last_del