From 812493f30421e7e894b5d46b7c2bad17ad22ae81 Mon Sep 17 00:00:00 2001 From: Frisk Date: Wed, 27 Apr 2022 10:55:39 +0200 Subject: [PATCH] Fixed compatibility issues with newer MediaWiki By using my ability "Steal code" from RcGcDw --- src/misc.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/misc.py b/src/misc.py index 402944c..171b3c9 100644 --- a/src/misc.py +++ b/src/misc.py @@ -106,6 +106,17 @@ def profile_field_name(name, embed, lang): return _("unknown") +def class_searcher(attribs: list) -> str: + """Function to return classes of given element in HTMLParser on handle_starttag + + :returns a string with all of the classes of element + """ + for attr in attribs: + if attr[0] == "class": + return attr[1] + return "" + + class ContentParser(HTMLParser): current_tag = "" last_ins = None @@ -121,15 +132,16 @@ class ContentParser(HTMLParser): self.del_length = len(self.more) def handle_starttag(self, tagname, attribs): + classes = class_searcher(attribs).split(' ') if tagname == "ins" or tagname == "del": self.current_tag = tagname - if tagname == "td" and "diff-addedline" in attribs[0] and self.ins_length <= 1000: + if tagname == "td" and "diff-addedline" in classes and self.ins_length <= 1000: self.current_tag = "tda" self.last_ins = "" - if tagname == "td" and "diff-deletedline" in attribs[0] and self.del_length <= 1000: + if tagname == "td" and "diff-deletedline" in classes and self.del_length <= 1000: self.current_tag = "tdd" self.last_del = "" - if tagname == "td" and "diff-empty" in attribs[0]: + if tagname == "td" and "diff-empty" in classes: self.empty = True def handle_data(self, data):