Revision: 7562
Author: xqt
Date: 2009-10-29 12:12:59 +0000 (Thu, 29 Oct 2009)
Log Message:
-----------
cleanUpLinks: no leading space on new lines
Modified Paths:
--------------
trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py 2009-10-29 09:10:59 UTC (rev 7561)
+++ trunk/pywikipedia/cosmetic_changes.py 2009-10-29 12:12:59 UTC (rev 7562)
@@ -165,7 +165,8 @@
self.redirect = redirect
self.namespace = namespace
self.template = (self.namespace == 10)
-
+ self.talkpage = self.namespace >= 0 and self.namespace % 2 == 1
+
def change(self, text):
"""
Given a wiki source code text, returns the cleaned up version.
@@ -206,7 +207,7 @@
Makes sure that interwiki links are put to the correct position and
into the right order.
"""
- if pywikibot.calledModuleName() <> 'interwiki':
+ if not self.talkpage and pywikibot.calledModuleName() <>
'interwiki':
interwikiLinks = pywikibot.getLanguageLinks(text, insite = self.site)
text = pywikibot.replaceLanguageLinks(text, interwikiLinks, site = self.site,
template = self.template)
return text
@@ -253,6 +254,7 @@
titleWithSection = match.group('titleWithSection')
label = match.group('label')
trailingChars = match.group('linktrail')
+ newline = match.group('newline')
if not self.site.isInterwikiLink(titleWithSection):
# The link looks like this:
@@ -331,7 +333,7 @@
# text[[ title | name ]]text -> text [[title|name]] text
# text[[ title |name]]text -> text[[title|name]]text
# text[[title| name]]text -> text [[title|name]]text
- if hadLeadingSpaces:
+ if hadLeadingSpaces and not newline:
newLink = ' ' + newLink
if hadTrailingSpaces:
newLink = newLink + ' '
@@ -346,7 +348,7 @@
# group label is the alternative link title, that's everything between | and
].
# group linktrail is the link trail, that's letters after ]] which are part
of the word.
# note that the definition of 'letter' varies from language to language.
- linkR =
re.compile(r'\[\[(?P<titleWithSection>[^\]\|]+)(\|(?P<label>[^\]\|]*))?\]\](?P<linktrail>'
+ self.site.linktrail() + ')')
+ linkR =
re.compile(r'(?P<newline>[\n]*)\[\[(?P<titleWithSection>[^\]\|]+)(\|(?P<label>[^\]\|]*))?\]\](?P<linktrail>'
+ self.site.linktrail() + ')')
text = pywikibot.replaceExcept(text, linkR, handleOneLink, ['comment',
'math', 'nowiki', 'pre', 'startspace'])
return text
Show replies by date