Added function format_template_oneline.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 2 Feb 2016 21:10:44 +0000 (21:10 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 2 Feb 2016 21:10:44 +0000 (21:10 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@2457 7aebc617-e5e2-0310-91dc-80fb5f6d2477

tests/test_mwmarkup.py
wrpylib/mwmarkup.py

index 1f2e939fa424d35eaa488d114ff68aff3db14cbe..9ddbb07da4447b3d0410d3b2106b2a9c5148ba7f 100644 (file)
@@ -141,3 +141,10 @@ class TestMwParserFromHell(unittest.TestCase):
         wikicode = mwparserfromhell.parse(wikitext)
         tag = next(wikicode.ifilter_tags())
         self.assertEqual('tag', tag.tag)
+
+
+class TestFormatTemplate(unittest.TestCase):
+    def test_format_template_oneline(self):
+        value = mwparserfromhell.parse('{{ my_template ||   | var = 7 }}').filter_templates()[0]
+        wrpylib.mwmarkup.format_template_oneline(value)
+        self.assertEqual('{{my_template| | |var=7}}', value)
index 2eb89c0d709a6223d98a12dc2321c7f60474360e..b593511ed43a47c97cc4bbb7278b1d6fcf4dbf05 100644 (file)
@@ -41,3 +41,16 @@ def format_template_table(template, keylen=None):
             param.value = ' {}\n'.format(value)
         else:
             param.value = '\n'
+
+
+def format_template_oneline(template):
+    """Formats a template like this: {{template_name|param| }}
+    (whitespace is stripped and empty parameters are replaced with one space)."""
+    template.name = template.name.strip()
+    for param in template.params:
+        if param.showkey:
+            param.name = param.name.strip()
+        value = param.value.strip()
+        if value == '':
+            value = ' '
+        param.value = value