diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 15:30:14 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 15:30:14 +0200 |
commit | 824ea3efa8d3c41e7c3429eae3ece97a5e384547 (patch) | |
tree | 6d59722da0d8690ef60ec4282929020289570ecd | |
parent | e846cbd2b18e43bdd69234930150f0cc97be984d (diff) | |
download | wikimini-824ea3efa8d3c41e7c3429eae3ece97a5e384547.tar.gz wikimini-824ea3efa8d3c41e7c3429eae3ece97a5e384547.tar.bz2 wikimini-824ea3efa8d3c41e7c3429eae3ece97a5e384547.zip |
Render {{main|...}} template
-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): |