diff --git a/output_html.py b/output_html.py index 14356aa..8e17f60 100644 --- a/output_html.py +++ b/output_html.py @@ -5,10 +5,10 @@ from anytree.importer import DictImporter from sys import argv -def build_rows_depth_first(node, rows, leaf_count=0): +def build_table_depth_first(node, rows, leaf_count=0): for child in sorted(node.children, key=lambda x: x.height, reverse=True): - leaf_count = build_rows_depth_first(child, rows, leaf_count) + leaf_count = build_table_depth_first(child, rows, leaf_count) colspan = 0 if node.siblings: @@ -34,6 +34,16 @@ def build_rows_depth_first(node, rows, leaf_count=0): return leaf_count +def generate_steps_depth_first(node, steps=[]): + for child in sorted(node.children, key=lambda x: x.height, reverse=True): + steps = generate_steps_depth_first(child, steps) + + if not node.is_leaf: + steps.append(node.description if node.description else node.name) + + return steps + + if len(argv) < 2: print(f"usage: {argv[0]} ") exit() @@ -61,9 +71,9 @@ print("

Steps

") print("
    ") for sub_recipe in sub_recipes: - tasks = [node for node in LevelOrderIter(sub_recipe) if not node.is_leaf] - for task in reversed(tasks): - print(f"
  1. {task.description if task.description else task.name}
  2. ") + tasks = generate_steps_depth_first(sub_recipe, steps=[]) + for task in tasks: + print(f"
  3. {task}
  4. ") print("
") @@ -75,7 +85,7 @@ for sub_recipe in sub_recipes: for i in range(len(sub_recipe.leaves)): output_rows.append([]) - build_rows_depth_first(sub_recipe, output_rows) + build_table_depth_first(sub_recipe, output_rows) for row in output_rows: print("")