From 0c034d016788d4d946c83df825819951bbb860ac Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 16 Aug 2021 16:51:10 +0200 Subject: Add rendering for {{quote|...}} templates --- wikimini/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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): -- cgit v1.2.3