Skip to content

Instantly share code, notes, and snippets.

@stewartknapman
Created August 28, 2015 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stewartknapman/2e28f38aca6623ffa48f to your computer and use it in GitHub Desktop.
Save stewartknapman/2e28f38aca6623ffa48f to your computer and use it in GitHub Desktop.
{% comment Note:
Takes a block of content, separates out the images from the text and then wraps
them in markup so that they can be displayed in columns side by side.
We split the content on tags and spaces then scan through it all looking for the things we want.
Why?! Because reasons!
%}{% endcomment %}
{% comment note: Split content %}{% endcomment %}
{% assign split = content_split | split:' ' | join:'~~' | replace: '>', '>~~' | replace: '<', '~~<' | split: '~~' %}
{% comment note: Find all the images %}{% endcomment %}
{% assign in_img = false %}
{% capture images %}{% endcapture %}
{% for s in split %}
{% unless s == blank %}
{% if s == '<img' %}
{% assign in_img = true %}
{% endif %}
{% if in_img %}
{% capture images %}{{ images }} {{ s }}{% endcapture %}
{% endif %}
{% if in_img and s contains '>' %}
{% assign in_img = false %}
{% endif %}
{% endunless %}
{% endfor %}
{% assign images = images | replace: ' <','~~<' | split: '~~' %}
{% assign content = content_split %}
{% for image in images %}
{% assign content = content | remove: image %}
{% endfor %}
{% assign content = content | remove: '<p></p>' %}
{% comment note: Output content %}{% endcomment %}
<div class="content-split">
<div class="content-split-text">
{{ content }}
</div>
<div class="content-split-images">
{% for image in images %}
{{ image }}
{% endfor %}
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment