{# BRANCHING #}
{%- macro summarize(unit) -%}
{# The label class is added to style the combination of item + caption in styles.css #}
{%- set clean_item = unit.item|default('Container')|string -%}
{%- if clean_item|is_hidden -%}
{%- if unit.caption -%}
{{unit.caption}}
{%- endif -%}
{%- else -%}
{{clean_item}}
{%- if unit.caption -%}
{{unit.caption}}{# Using literal (instead of adding a css style) makes converting from html to text easier. #}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{%- macro create_branch(unit) -%}
{{ summarize(unit)}} {# Create the label based on and tags #}
{%- if unit.content -%}
{{unit.content|trim|safe|md_to_html }} {# Needs to be safe since some unit content may have html #}
{%- endif -%}
{% if unit|is_par %}
{% endif %}
{%- endmacro -%}
{%- macro create_branches(units) -%}
{%- if units -%}
{%- for unit in units -%}
-
{{ create_branch(unit) }}
{%- set target_units = unit.units|from_json -%}
{%- if target_units -%}
{# determine whether par. 1 is in next ul tag or ul to start with par. 2.. #}
{%- set child = target_units[0] -%}
{%- if child|is_first_par -%}
{{ create_branch(child) }}
{{ create_branches(child.units) }}
{% if target_units|length > 1 -%}
{%- set target_units = target_units[1:] -%}
{{ create_branches(target_units) }}
{%- endif -%}
{% else %}
{{ create_branches(target_units) }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
{%- macro connect_breadcrumbs(units) -%}
{% for unit in units -%}
{{ unit|crumb }}
{%- endfor %}
{%- endmacro -%}
{%- macro create_paragraphs(units) -%}
{% if units %}
{%- for unit in units -%}
{{ unit|paragrapher }}
{{ create_paragraphs(unit.units|from_json) }}
{%- endfor -%}
{% endif %}
{%- endmacro -%}