From 76531e3cfcb4692e2d2a2f2898bd686c8580d74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Fri, 4 Nov 2022 00:33:05 +0100 Subject: [PATCH] Add result box rendering. --- scripts/generate.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index 8e27fde..0820493 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -11,6 +11,7 @@ import uuid from datetime import datetime import traceback import re +from itertools import chain import inotify.adapters @@ -399,10 +400,10 @@ def render_list_item(element, acc, headline, graph): render_text_tokens(element.content, acc, headline, graph) acc.append("") - -def render_code_block(element, acc, headline, graph): - acc.append('
'.format(element.subtype.lower()))
-    content = html.escape(element.lines)
+def render_block(content, acc, _class, is_code):
+    acc.append('
'.format(_class))
+    if is_code:
+        acc.append('')
 
     # Remove indentation common to all lines
     base_indentation = min([
@@ -416,14 +417,21 @@ def render_code_block(element, acc, headline, graph):
     ]
 
     acc.append('\n'.join(content_lines))
-    acc.append('
') + if is_code: + acc.append('
') + acc.append('
') + +def render_code_block(element, acc, headline, graph): + content = html.escape(element.lines) + render_block(content, acc, _class='code ' + element.subtype.lower(), is_code=True) + def render_results_block(element, acc, headline, graph): - # TODO: - # acc.append('
')
-    # render_tree(element.children, acc)
-    # acc.append('
') - pass + items = [e.get_raw() for e in element.children] + print(items) + content = '\n'.join(items) + if len(content.strip()) > 0: + render_block(content, acc, _class='results lang-text', is_code=False) def render_org_text(element, acc, headline, graph): as_dom = org_rw.text_to_dom(element.contents, element) @@ -436,6 +444,8 @@ def render_text(element, acc, headline, graph): def render_text_tokens(tokens, acc, headline, graph): acc.append('

') + if isinstance(tokens, org_rw.Text): + tokens = tokens.contents for chunk in tokens: if isinstance(chunk, str): lines = chunk.split('\n\n')