jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] cosmetic_changes: merge similar regexes ......................................................................
[IMPROV] cosmetic_changes: merge similar regexes
Instead of having two pretty similar regexes it's in most cases possible to combine them easily. This is also fixing “dash” into “pipe” in the comment explaining how the external link fixer works.
It also adds the site parameter to each changed call.
Change-Id: I8513e34f873730ee9c92abb75c499f67cb3d86fc (cherry picked from commit 20b2b6bcd7be359fa7007a0a5c224a8692eb88e6) --- M pywikibot/cosmetic_changes.py 1 file changed, 14 insertions(+), 26 deletions(-)
Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index 57a2c78..31de09d 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -712,17 +712,13 @@ # r'[https?://%s.%s.org/wiki/(?P<link>\S+)\s+(?P<title>.+?)\s?]' # % (self.site.code, self.site.family.name), # r'[[\g<link>|\g<title>]]', exceptions) - # external link in double brackets + # external link in/starting with double brackets text = textlib.replaceExcept( text, - r'[[(?P<url>https?://[^]]+?)]]', - r'[\g<url>]', exceptions) - # external link starting with double bracket - text = textlib.replaceExcept(text, - r'[[(?P<url>https?://.+?)]', - r'[\g<url>]', exceptions) - # external link and description separated by a dash, with - # whitespace in front of the dash, so that it is clear that + r'[[(?P<url>https?://[^]]+?)]]?', + r'[\g<url>]', exceptions, site=self.site) + # external link and description separated by a pipe, with + # whitespace in front of the pipe, so that it is clear that # the dash is not a legitimate part of the URL. text = textlib.replaceExcept( text, @@ -742,14 +738,10 @@ # Keep in mind that MediaWiki automatically converts <br> to <br /> exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace'] - text = textlib.replaceExcept(text, r'(?i)<b>(.*?)</b>', r"'''\1'''", - exceptions) - text = textlib.replaceExcept(text, r'(?i)<strong>(.*?)</strong>', - r"'''\1'''", exceptions) - text = textlib.replaceExcept(text, r'(?i)<i>(.*?)</i>', r"''\1''", - exceptions) - text = textlib.replaceExcept(text, r'(?i)<em>(.*?)</em>', r"''\1''", - exceptions) + text = textlib.replaceExcept(text, r'(?i)<(b|strong)>(.*?)</\1>', + r"'''\2'''", exceptions, site=self.site) + text = textlib.replaceExcept(text, r'(?i)<(i|em)>(.*?)</\1>', + r"''\2''", exceptions, site=self.site) # horizontal line without attributes in a single line text = textlib.replaceExcept(text, r'(?i)([\r\n])<hr[ /]*>([\r\n])', r'\1----\2', exceptions) @@ -800,19 +792,15 @@ exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace', 'gallery', 'hyperlink', 'interwiki', 'link'] # change <number> ccm -> <number> cm³ - text = textlib.replaceExcept(text, r'(\d)\s* ccm', - r'\1 ' + u'cm³', exceptions) - text = textlib.replaceExcept(text, - r'(\d)\s*ccm', r'\1 ' + u'cm³', - exceptions) + text = textlib.replaceExcept(text, r'(\d)\s*(?: )?ccm', + r'\1 cm³', exceptions, + site=self.site) # Solve wrong Nº sign with °C or °F # additional exception requested on fr-wiki for this stuff pattern = re.compile(u'«.*?»', re.UNICODE) exceptions.append(pattern) - text = textlib.replaceExcept(text, r'(\d)\s* ' + u'[º°]([CF])', - r'\1 ' + u'°' + r'\2', exceptions) - text = textlib.replaceExcept(text, r'(\d)\s*' + u'[º°]([CF])', - r'\1 ' + u'°' + r'\2', exceptions) + text = textlib.replaceExcept(text, r'(\d)\s*(?: )?[º°]([CF])', + r'\1 °\2', exceptions, site=self.site) text = textlib.replaceExcept(text, u'º([CF])', u'°' + r'\1', exceptions) return text