From 824ea3efa8d3c41e7c3429eae3ece97a5e384547 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 16 Aug 2021 15:30:14 +0200 Subject: Render {{main|...}} template --- wikimini/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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): -- cgit v1.2.3