diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 16:51:10 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-16 16:51:10 +0200 |
commit | 0c034d016788d4d946c83df825819951bbb860ac (patch) | |
tree | b2b1fd492a842d2c1e9c4676af8f5211ee6cf2b1 | |
parent | 46e89b622ad24ed12a0aefad5551a4e1497e6270 (diff) | |
download | wikimini-0c034d016788d4d946c83df825819951bbb860ac.tar.gz wikimini-0c034d016788d4d946c83df825819951bbb860ac.tar.bz2 wikimini-0c034d016788d4d946c83df825819951bbb860ac.zip |
Add rendering for {{quote|...}} templates
-rw-r--r-- | wikimini/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/wikimini/__init__.py b/wikimini/__init__.py index e6bc513..d034d30 100644 --- a/wikimini/__init__.py +++ b/wikimini/__init__.py @@ -96,6 +96,22 @@ def render_main(obj: mwp.nodes.template.Template) -> str: return "Main articles:\n{}\n".format("\n".join(links)) +def render_quote(obj): + text = obj.get("text", None) + if not text: + return "" + content = _convert(text.value) + lines = content.split("\n") + return "\n".join(f"> {line}" for line in lines) + + +def render_cquote(obj): + text = obj.params[0] + content = _convert(text.value) + lines = content.split("\n") + return "\n".join(f"> {line}" for line in lines) + + 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 @@ -193,6 +209,10 @@ def _convert(obj: Union[mwp.nodes.Node, mwp.wikicode.Wikicode]) -> str: return "pronounced [{}]".format(_convert(obj.params[0].value)) elif name in {"main", "main article"}: return render_main(obj) + elif name in {"quote", "blockquote"}: + return render_quote(obj) + elif name == "cquote": + return render_cquote(obj) else: return default(obj) elif isinstance(obj, mwp.nodes.wikilink.Wikilink): |