summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-16 16:51:10 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-16 16:51:10 +0200
commit0c034d016788d4d946c83df825819951bbb860ac (patch)
treeb2b1fd492a842d2c1e9c4676af8f5211ee6cf2b1
parent46e89b622ad24ed12a0aefad5551a4e1497e6270 (diff)
downloadwikimini-0c034d016788d4d946c83df825819951bbb860ac.tar.gz
wikimini-0c034d016788d4d946c83df825819951bbb860ac.tar.bz2
wikimini-0c034d016788d4d946c83df825819951bbb860ac.zip
Add rendering for {{quote|...}} templates
-rw-r--r--wikimini/__init__.py20
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):