Problem/Motivation
1) The caption filter currently always wraps the captioned element in a <figure>
block to which it adds its own <figcaption>
. This creates unnessecarily nested markup in case the element itself is already presented as/contains a <figure>
with a <figcaption>
.
2) Additionally, the $node->C14N()
call strips all comments, which includes Twig debug comments (we can deal with that) and compatibility comments like those used for responsive images: <!--[if IE 9]><video style="display: none;"><![endif]-->
(this is bad and will cause problems).
Example setup for 1) using entity_embed
:
- Media type "Image" with a template like
<figure>{{ content.field_image }}<figcaption>{{ name }}</figcaption></figure>
- Some content in which the media entity is embedded with a specified custom caption
Expected result:<figure>{{ content.field_image }}<figcaption>{{ my overridden caption}}</figcaption></figure>
Actual result (using default filter-caption.html.twig
):
<figure>
<figure>
{{ content.field_image }}
<figcaption>{{ name }}</figcaption>
</figure>
<figcaption>{{ my overridden caption }}</figcaption>
</figure>
Proposed resolution
1) Re-use an already present <figcaption>
element.
2) Keep comments when building $altered_html
.
Remaining tasks
Discuss what we need/want to do. Review.