Fix closing tag of figures without captions in lists (#2697)

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.
This commit is contained in:
Leo 2020-10-28 11:43:09 -07:00 committed by GitHub
parent 50bd68e6d0
commit c2c05b9b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,9 @@
<figure class="{{ include.class }}"> <figure class="{{ include.class }}">
<img src="{{ include.image_path | relative_url }}" <img src="{{ include.image_path | relative_url }}"
alt="{% if include.alt %}{{ include.alt }}{% endif %}"> alt="{% if include.alt %}{{ include.alt }}{% endif %}">
{% if include.caption %} {%- if include.caption -%}
<figcaption> <figcaption>
{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }} {{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
</figcaption> </figcaption>
{% endif %} {%- endif -%}
</figure> </figure>