diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-21 22:40:21 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-21 22:40:21 +0200 |
commit | 03d253975e9400943083770da6d16c127355fc2a (patch) | |
tree | 4612a97cfbb07dbc134ac9a275b5aeb1aef4fc78 /wikimini/templates | |
parent | 4fc3802d8f1455d5156ef5b185a70353752c461f (diff) | |
download | wikimini-03d253975e9400943083770da6d16c127355fc2a.tar.gz wikimini-03d253975e9400943083770da6d16c127355fc2a.tar.bz2 wikimini-03d253975e9400943083770da6d16c127355fc2a.zip |
Remove Document return type from convert
It doesn't really make sense to make the output that dependent on the
input type. convert_to_document basically does the same - ensuring that
the output is a Document. Templates that call convert recursively can
also call convert_to_document.
Furthermore, since we now pass very short Wikicode into
convert_to_document, there was an exception being raised if there were
less than 2 nodes. This seems to be because of a "smart list" that
mwparserfromhell uses internally, which didn't properly slice if the end
index is out of bounds.
Diffstat (limited to 'wikimini/templates')
-rw-r--r-- | wikimini/templates/language.py | 10 | ||||
-rw-r--r-- | wikimini/templates/quotes.py | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/wikimini/templates/language.py b/wikimini/templates/language.py index 22320da..7579c34 100644 --- a/wikimini/templates/language.py +++ b/wikimini/templates/language.py @@ -8,7 +8,7 @@ import pycountry def tmpl_ipa(wikimini, obj): """Renders the ``{{IPA|...}}`` template.""" return [Plain("pronounced [{}]".format( - wikimini.convert(obj.params[0].value).plain() + wikimini.convert_to_document(obj.params[0].value).plain() ))] @@ -17,7 +17,7 @@ registry.insert("IPA", tmpl_ipa) def tmpl_lang(wikimini, obj): """Renders the ``{{Lang|...}}`` template.""" - return wikimini.convert(obj.params[1].value).nodes() + return wikimini.convert_to_document(obj.params[1].value).nodes() registry.insert("lang", tmpl_lang) @@ -28,7 +28,8 @@ def tmpl_lang_code(language_name): """Creates a template renderer for a ``{{lang-xx|...}}`` template.""" def inner(wikimini, obj): return [Plain("{}: {}".format( - language_name, wikimini.convert(obj.params[0].value).plain() + language_name, + wikimini.convert_to_document(obj.params[0].value).plain(), ))] return inner @@ -37,7 +38,8 @@ def tmpl_ipa_code(language_name): """Creates a template renderer for a ``{{IPA-xx|...}}`` template.""" def inner(wikimini, obj): return [Plain("{} pronunciation: [{}]".format( - language_name, wikimini.convert(obj.params[0].value).plain() + language_name, + wikimini.convert_to_document(obj.params[0].value).plain(), ))] return inner diff --git a/wikimini/templates/quotes.py b/wikimini/templates/quotes.py index 00b82fb..5951543 100644 --- a/wikimini/templates/quotes.py +++ b/wikimini/templates/quotes.py @@ -9,7 +9,7 @@ def tmpl_quote(wikimini, obj): text = obj.get("text", None) if not text: return "" - content = wikimini.convert(text.value).nodes() + content = wikimini.convert_to_document(text.value).nodes() return [BlockQuote(Paragraph(content))] @@ -20,7 +20,7 @@ registry.insert("quote", tmpl_quote) def tmpl_cquote(wikimini, obj): """Renders the ``{{cquote|...}}`` template.""" text = obj.params[0] - content = wikimini.convert(text.value).nodes() + content = wikimini.convert_to_document(text.value).nodes() return [BlockQuote(Paragraph(content))] |