Skip to content

Instantly share code, notes, and snippets.

@kinngh
Last active February 26, 2024 17:43
Show Gist options
  • Save kinngh/51899affffb039f98c42e1d6291745a6 to your computer and use it in GitHub Desktop.
Save kinngh/51899affffb039f98c42e1d6291745a6 to your computer and use it in GitHub Desktop.
Packing slips doesn't support rich text fields via the `| metafield_tag` just yet, this parses the rich text JSON into usable HTML
{% assign parsed_content = order.metafields.namespace.key | json_parse %}
{% for item in parsed_content.children %}
{% case item.type %}
{% when 'paragraph' %}
<p>
{% for child in item.children %}
{% if child.bold and child.italic %}
<strong><em>{{ child.value }}</em></strong>
{% elsif child.bold %}
<strong>{{ child.value }}</strong>
{% elsif child.italic %}
<em>{{ child.value }}</em>
{% else %}
{{ child.value }}
{% endif %}
{% endfor %}
</p>
{% when 'heading' %}
{% assign heading_size = 'h' | append: item.level %}
<{{ heading_size }}>
{% for child in item.children %}
<span {% if child.italic %}style="font-style: italic;"{% endif %}>
{{ child.value }}
</span>
{% endfor %}
</{{ heading_size }}>
{% when 'link' %}
<a href="{{ item.url }}" title="{{ item.title }}">
{% for child in item.children %}
{{ child.value }}
{% endfor %}
</a>
{% when 'list' %}
{% if item.listType == 'ordered' %}
<ol>
{% else %}
<ul>
{% endif %}
{% for list_item in item.children %}
<li>
{% for child in list_item.children %}
{{ child.value }}
{% endfor %}
</li>
{% endfor %}
{% if item.listType == 'ordered' %}
</ol>
{% else %}
</ul>
{% endif %}
{% endcase %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment