Created
August 28, 2015 04:53
-
-
Save stewartknapman/2e28f38aca6623ffa48f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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