{%- macro summarize(node) -%}
{# The label class is added to style the combination of item + caption in styles.css #}
{%- set clean_item = node.item|default('Container')|string -%}
{%- if clean_item|is_hidden -%}
{%- if node.caption -%}
{{node.caption}}
{%- endif -%}
{%- else -%}
{{clean_item}}
{%- if node.caption -%}
{{node.caption}}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{%- macro create_branch(node) -%}
{{ summarize(node)}} {# Create the label based on and tags #}
{%- if node.content -%}
{{node.content|trim|safe|md_to_html }} {# Needs to be safe since some unit content may have html #}
{%- endif -%}
{%- if node|is_par -%}
{%- endif -%} {# Fill missing node since paragraphs will not have a clickable prefix e.g Art. 1, Sec. 5, etc. #}
{%- endmacro -%}
{# special rule: check on the first child to determine whether it should form part of the ul tag or whether only ul to start with paragraph 2 onwards #}
{# id relevant for branch unit; this enables a hook to referenced instances #}
{# data-par relevant so that this can indented via a css #}
{%- macro create_branches(units) -%}
{%- for unit in units -%}
- {{ create_branch(unit) }}
{%- set target_units = unit.units|from_json -%}
{%- if target_units -%}
{% set child = target_units[0] %}
{%- if child|is_par and target_units|length > 1 -%}
{{ create_branch(child) }}
{% if child.units %}
{{ create_branches(child.units) }}
{% endif %}
{%- set target_units = target_units[1:] -%}
{% endif %}
{{ create_branches(target_units) }}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro connect_breadcrumbs(nodes) -%}
{% for node in nodes -%}
{{ node|crumb }}
{%- endfor %}
{%- endmacro -%}