diff options
Diffstat (limited to 'wikimini/templates/cite.py')
-rw-r--r-- | wikimini/templates/cite.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/wikimini/templates/cite.py b/wikimini/templates/cite.py new file mode 100644 index 0000000..ac4f597 --- /dev/null +++ b/wikimini/templates/cite.py @@ -0,0 +1,36 @@ +"""Citation related templates.""" +from . import registry + + +def tmpl_citation(wikimini, obj): + """Renders the ``{{citation|...}}`` template.""" + title = obj.get("title", None) + if title: + title = title.value.strip_code().strip() + else: + title = "Untitled" + names = [] + for idx in ["%", "%1", "%2", "%3", "%4", "%5", "editor1-%"]: + last = obj.get(idx.replace("%", "last"), None) + if last: + last = last.value.strip_code().strip() + first = obj.get(idx.replace("%", "first"), None) + if first: + first = first.value.strip_code().strip() + if last and first: + names.append(f"{last}, {first}") + elif last: + names.append(last) + elif first: + names.append(first) + return "{} ({})".format(title, "; ".join(names)) + + +for name in ["cite", "citation", "cite arXiv", "cite AV media", "cite book", + "cite conference", "cite encyclopedia", "cite episode", + "cite interview", "cite journal", "cite magazine", + "cite mailing list", "cite map", "cite news", "cite newsgroup", + "cite podcast", "cite press release", "cite report", + "cite serial", "cite sign", "cite speech", "cite techreport", + "cite thesis", "cite web"]: + registry.insert(name, tmpl_citation) |