#!/usr/bin/python3.4
-# coding=utf-8
# $Id$
# $HeadURL$
"""For parsing MediaWiki text, we rely on the package mwparserfromhell (https://github.com/earwig/mwparserfromhell).
pass
-def template_to_table(template, keylen=None):
+def format_template_table(template, keylen=None):
"""Reformat the given template to be tabular.
>>> template
{{foo|bar|bazz=7}}
- >>> template_to_table(template)
+ >>> format_template_table(template)
{{foo
| bar
| bazz = 7
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
+
+
+def dbkey_to_title(value):
+ """Converts a article database key to a article title. Private function secureAndSplit() of the Title class
+ on line 3316 of includes/Title.php says:
+ $this->mTextform = str_replace( '_', ' ', $this->mDbkeyform );
+ No check for None because a missing title is an error."""
+ return value.replace('_', ' ')