Skip to content

Commit

Permalink
Fix closing tag of figures without captions in lists (#2697)
Browse files Browse the repository at this point in the history
When the figure helper is used in a list, which can be either ordered or
unordered, and no caption is specified, a line with text "</figure>"
will be shown below the figure on the rendered page.

This is because, if the '{% if include.caption %}' evaluates to false,
the lines between that 'if' statement and '{% endif %}' will be emptied,
not removed, so the block will be filled by empty lines.

HTML ignores redundant empty lines, but Markdown takes them seriously.
In addition, Markdown expects proper indentation of lines inside lists,
and the closing '</figure>' tag is not indented.  When combined, the
empty space and absence of indentation cause Markdown to process the
'</figure>' tag as a separate paragraph instead of an HTML tag, thus the
text for the tag is directly rendered on the page.

The fix for this issue is very simple: remove the empty space when
'include.caption' is false.  As described in
<https://shopify.github.io/liquid/basics/whitespace/>, this can be done
by adding hyphens to the 'if' and 'endif' tags.
  • Loading branch information
Leo3418 authored Oct 28, 2020
1 parent 50bd68e commit c2c05b9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _includes/figure
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<figure class="{{ include.class }}">
<img src="{{ include.image_path | relative_url }}"
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
{% if include.caption %}
{%- if include.caption -%}
<figcaption>
{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
</figcaption>
{% endif %}
{%- endif -%}
</figure>

0 comments on commit c2c05b9

Please sign in to comment.