diff options
-rw-r--r-- | wikimini/__init__.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/wikimini/__init__.py b/wikimini/__init__.py index 032639a..790170f 100644 --- a/wikimini/__init__.py +++ b/wikimini/__init__.py @@ -86,6 +86,14 @@ def render_cite_book(obj: mwp.nodes.template.Template) -> str: return "{} ({})".format(title, "; ".join(names)) +def render_main(obj: mwp.nodes.template.Template) -> str: + """Renders the {{main|...}} template.""" + links = [ + "=> {} {}".format(page_url(str(t.value)), t.value) for t in obj.params + ] + return "Main articles:\n{}\n".format("\n".join(links)) + + def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: default = lambda obj: mwp.wikicode.Wikicode([obj]).strip_code(collapse=False) # This does the actual conversion @@ -160,6 +168,8 @@ def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: return render_reign(obj) elif name in {"cite book", "cite journal", "cite news"}: return render_cite_book(obj) + elif name == "main": + return render_main(obj) else: return default(obj) elif isinstance(obj, mwp.nodes.wikilink.Wikilink): |