I'm outputting an attachment image's caption but feel I should escape the output:
<figcaption> <?php echo get_post( get_post_thumbnail_id() )->post_excerpt; ?> </figcaption>
I was tempted to use
esc_html( get_post( get_post_thumbnail_id() )->post_excerpt ) but the caption may contain legitimate markup such as
<a href=""></a> etc.
How should I escape image attachment caption text considering it may contain markup I'd like to keep?