diff --git a/lib/redfam.py b/lib/redfam.py index 36ff4d2..f645ae7 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -611,22 +611,22 @@ class RedFamWorker( RedFam ): @rtype str """ - # We need to Replace Links with their linktext - anchor_code = mwparser.parse( self.heading.strip() ) - for link in anchor_code.ifilter_wikilinks(): - if link.text: - text = link.text - else: - text = link.title + # Expand templates using pwb site object + site = pywikibot.Site() + anchor_code = site.expand_text(self.heading.strip()) - anchor_code.replace( link, text ) + # Remove possibly embbeded files + anchor_code = re.sub( r"\[\[\w+:[^\|]+(?:\|.+){2,}\]\]", "", + anchor_code ) - # Whitespace is replaced with underscores - anchor_code.replace( " ", "_" ) + # Replace non-breaking-space by correct urlencoded value + anchor_code = anchor_code.replace( " ", ".C2.A0" ) - # We try it with out any more parsing as mw will do while parsing page - return ( self.redpage.pagetitle + "#" + - str(anchor_code).strip() ) + # Use mwparser to strip and normalize + anchor_code = mwparser.parse( anchor_code ).strip_code() + + # We try it without any more parsing as mw will do while parsing page + return ( self.redpage.pagetitle + "#" + anchor_code.strip() ) def generate_disc_notice_template( self ): """