mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Merge branch 'horse-wikibot-edit-diff-sync' into 'testing'
Sync diff parser with Wiki-Bot: Fix moved lines edit diff See merge request piotrex43/RcGcDw!92
This commit is contained in:
commit
810fb31311
|
@ -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)
|
||||
|
|
11
src/misc.py
11
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
|
||||
|
|
Loading…
Reference in a new issue