Created
May 1, 2018 05:14
-
-
Save stewartknapman/def11aefd1a95a6028139d5df4b210e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 %} | |
Remove orphans from a string of text by adding a non-breaking space between the last two words. | |
Usage: {% include 'adopt' string: 'my string' %} | |
{% endcomment %} | |
{%- assign string_parts = string | split: ' ' -%} | |
{%- assign last_part = string_parts | last -%} | |
{% if last_part contains ' ' %} | |
{{ string }} | |
{% else %} | |
{%- assign last_part_nbsp = last_part | prepend: ' ' -%} | |
{%- assign string_nbsp = string | replace: last_part, last_part_nbsp | replace: ' ', ' ' -%} | |
{{ string_nbsp }} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment