From d52ea2bd4b2e6fa9aa0e0f3248416d410e17f1da Mon Sep 17 00:00:00 2001 From: Dmitry Mottl Date: Sat, 11 Aug 2018 16:46:52 +0300 Subject: [PATCH 1/2] Remove File/Image links in strip_code() --- mwparserfromhell/nodes/wikilink.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mwparserfromhell/nodes/wikilink.py b/mwparserfromhell/nodes/wikilink.py index 8f4bf7d..f401af7 100644 --- a/mwparserfromhell/nodes/wikilink.py +++ b/mwparserfromhell/nodes/wikilink.py @@ -31,6 +31,25 @@ __all__ = ["Wikilink"] class Wikilink(Node): """Represents an internal wikilink, like ``[[Foo|Bar]]``.""" + # a list of links to strip: + strip_links = ['File', 'Image', 'Media', # English + 'Файл', 'Изображение', # Russian + 'Detei', # German + 'Fichier', # French + 'Archivo', # Spanish + 'Immagine', # Italiano + 'Imagem' # Portuguese + 'Plik' # Polish + 'Berkas', # Indonesian + 'Bestand', # Netherlands + 'चित्र', # Hindi + 'Payl', # Cebuano + 'Paypay', # Waray + 'Tập_tin', # Vietnamese + 'ファイル', # Japanese + # -- add here other start words of image wikilinks -- + ] + def __init__(self, title, text=None): super(Wikilink, self).__init__() self._title = title @@ -47,6 +66,10 @@ class Wikilink(Node): yield self.text def __strip__(self, **kwargs): + _title = self.title.lstrip(':') + for word in self.strip_links: + if _title.startswith(word): + return '' if self.text is not None: return self.text.strip_code(**kwargs) return self.title.strip_code(**kwargs) From c6e813c5feddcf02bf4bd409618bbc3ca11b4d40 Mon Sep 17 00:00:00 2001 From: Dmitry Mottl Date: Sat, 11 Aug 2018 18:26:05 +0300 Subject: [PATCH 2/2] syntax issue --- mwparserfromhell/nodes/wikilink.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mwparserfromhell/nodes/wikilink.py b/mwparserfromhell/nodes/wikilink.py index f401af7..9b4a9ac 100644 --- a/mwparserfromhell/nodes/wikilink.py +++ b/mwparserfromhell/nodes/wikilink.py @@ -38,15 +38,15 @@ class Wikilink(Node): 'Fichier', # French 'Archivo', # Spanish 'Immagine', # Italiano - 'Imagem' # Portuguese - 'Plik' # Polish + 'Imagem', # Portuguese + 'Plik', # Polish 'Berkas', # Indonesian 'Bestand', # Netherlands 'चित्र', # Hindi - 'Payl', # Cebuano - 'Paypay', # Waray + 'Payl', # Cebuano + 'Paypay', # Waray 'Tập_tin', # Vietnamese - 'ファイル', # Japanese + 'ファイル', # Japanese # -- add here other start words of image wikilinks -- ]