Revision: 4235
Author: wikipedian
Date: 2007-09-11 12:57:06 +0000 (Tue, 11 Sep 2007)
Log Message:
-----------
replaceExcept(): handle nested templates (up to level 2)
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-09-11 12:47:08 UTC (rev 4234)
+++ trunk/pywikipedia/wikipedia.py 2007-09-11 12:57:06 UTC (rev 4235)
@@ -2574,10 +2574,15 @@
'startspace': re.compile(r'(?m)^ (.*?)$'),
# tables often have whitespace that is used to improve wiki
# source code readability.
+ # TODO: handle nested tables.
'table':
re.compile(r'(?ims)^{\|.*?^\|}|<table>.*?</table>'),
# templates with parameters often have whitespace that is used to
# improve wiki source code readability.
- 'template': re.compile(r'(?s){{.*?}}'),
+ # 'template': re.compile(r'(?s){{.*?}}'),
+ # The regex above fails on nested templates. This regex can handle
+ # templates inside templates, but no deeper cascades.
+ 'template': re.compile(r'(?s){{(({{.*?}})?.*?)*}}'),
+
}
# if we got a string, compile it as a regular expression
Show replies by date