From dd2654588ccca5abb4c13f4e99c33a8a34eb9ab2 Mon Sep 17 00:00:00 2001 From: "j.vondoemming" <j.vondoemming@stud.uni-goettingen.de> Date: Sat, 13 Aug 2022 11:57:53 +0200 Subject: [PATCH] implemented definition lists --- fgs/pandoc.py | 24 +++++++++++++++++++- theme/static/css/main.css | 12 ++++++++++ theme/templates/macros/content_renderer.html | 16 +++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/fgs/pandoc.py b/fgs/pandoc.py index 5218451..1e3782a 100644 --- a/fgs/pandoc.py +++ b/fgs/pandoc.py @@ -308,6 +308,28 @@ class BlockContainer(Block): # Attr [Block] self.content = self.parse_blocks(pandocraw[1]) # TODO handle alerts +class BlockDefinitionList(Block): # [([Inline], [[Block]])] + etype = "definitionlist" + def parse_internal(self, pandocraw): + """ + [ + [ + [{'t': 'Str', 'c': 'AStA'}], + [ + [{'t': 'Plain', 'c': [{'t': 'Str', 'c': 'Allgemeiner'}, {'t': 'Space'}, {'t': 'Str', 'c': 'studierenden'}, {'t': 'Space'}, {'t': 'Str', 'c': 'Ausschuss'}]}] + ] + ] + ] + """ + self.items = [] + for rawitem in pandocraw: + item = {} + item["term"] = self.parse_inlines(rawitem[0]) + item["definitions"] = [] + for rawdefinition in rawitem[1]: + item["definitions"].append(self.parse_blocks(rawdefinition)) + self.items.append(item) + ############################## INLINE ######################################### class Inline(Element): @@ -425,7 +447,7 @@ block_parsing_register = { "OrderedList" : BlockOrderedList, "HorizontalRule": BlockHorizontalRule, "Table" : {"TODO": True,}, # Attr Caption [ColSpec] TableHead [TableBody] TableFoot - "DefinitionList": {"TODO": True,}, # [([Inline], [[Block]])] + "DefinitionList": BlockDefinitionList, #"LineBlock" :{"type":"lineblock", "TODO": True, "c" : [] }, # [[Inline]] # TODO find file that triggers LineBlock #"Null" :{"type":"nothing" }, # TODO find file that triggers Null } diff --git a/theme/static/css/main.css b/theme/static/css/main.css index cd81b63..1eba207 100644 --- a/theme/static/css/main.css +++ b/theme/static/css/main.css @@ -410,6 +410,18 @@ sup { margin: 0 0 1em 0; } +.content dt { + font-weight: bold; +} +.content dt::after { + content: ': ' +} + +.content dd { + margin-left: 1em; + margin-bottom: 0.1em; +} + .content ul, .content ol { padding-left: 2em; diff --git a/theme/templates/macros/content_renderer.html b/theme/templates/macros/content_renderer.html index 4b0a747..a3429bc 100644 --- a/theme/templates/macros/content_renderer.html +++ b/theme/templates/macros/content_renderer.html @@ -118,6 +118,8 @@ {{ render_block_rawblock(block, lang) }} {%- elif etype == "orderedlist" -%} {{ render_block_orderedlist(block, lang) }} + {%- elif etype == "definitionlist" -%} + {{ render_block_definitionlist(block, lang) }} {%- else -%} <br><strong>ERROR: Unhandled block type: '{{ etype|e }}'</strong><br> {%- endif -%} @@ -208,6 +210,20 @@ </ol> {%- endmacro -%} +{%- macro render_block_definitionlist(block, lang) -%} + {%- set items = block['items'] -%} + <dl> + {%- for item in items -%} + {%- set term = item['term'] -%} + {%- set definitions = item['definitions'] -%} + <dt>{{ render_inlines(term, lang) }}</dt> + {%- for def in definitions -%} + <dd>{{ render_blocks(def, lang) }}</dd> + {%- endfor -%} + {%- endfor -%} + </dl> +{%- endmacro -%} + {#- ############################ INLINES ################################## -#} -- GitLab