diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-19 13:10:43 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-19 13:10:43 +0200 |
commit | 7871c99a5ef791a5ce24c4b1d016a8b4200baf34 (patch) | |
tree | d9d175d98bdece5720dc9da380d616026738f26a /wikimini/templates/mainlinks.py | |
parent | 469353899ae6d7d0c0b7b105c24baaa4841c6328 (diff) | |
download | wikimini-7871c99a5ef791a5ce24c4b1d016a8b4200baf34.tar.gz wikimini-7871c99a5ef791a5ce24c4b1d016a8b4200baf34.tar.bz2 wikimini-7871c99a5ef791a5ce24c4b1d016a8b4200baf34.zip |
Add an internal Document representation
Doing everything on strings is kinda wonky, so this adds an intermediate
representation. The idea behind this is that the pipeline now goes
Wikicode [1]-> Document [2]-> Output String
Where step 1 takes care of templates and everything, and step 2 does the
actual output formatting. This has the benefit that we can support
multiple output types, some with more and some with less features (e.g.,
adding a Markdown output which keeps some of the original formatting
intact), and it has the benefit of being less wonky (no hacks with
"<!NUM!>" for numbered lists, more streamlined formatting with newlines,
...).
Diffstat (limited to 'wikimini/templates/mainlinks.py')
-rw-r--r-- | wikimini/templates/mainlinks.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/wikimini/templates/mainlinks.py b/wikimini/templates/mainlinks.py index ffcbc5e..8c9abbf 100644 --- a/wikimini/templates/mainlinks.py +++ b/wikimini/templates/mainlinks.py @@ -1,14 +1,15 @@ """Renders templates that link to further articles.""" from . import registry +from ..document import Paragraph, Plain, BlockLink def tmpl_main(wikimini, obj): """Renders the ``{{main|...}}`` template.""" links = [ - "=> {} {}".format(wikimini.page_url(str(t.value)), t.value) + BlockLink(wikimini.page_url(str(t.value)), t.value.strip_code()) for t in obj.params ] - return "Main articles:\n{}\n".format("\n".join(links)) + return [Paragraph([Plain("Main articles:")])] + links registry.insert("main", tmpl_main) |