Skip to content

Commit

Permalink
Fix image caption generated by pandoc with fancybox enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Aug 28, 2021
1 parent e410399 commit c377515
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/css/_common/components/post/post-body.styl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
margin-left: 4px;
}

.image-caption, .figure .caption {
// For fancybox and pandoc
.image-caption, img + figcaption, .fancybox + figcaption {
color: $grey-dark;
font-size: $font-size-small;
font-weight: bold;
Expand Down
5 changes: 4 additions & 1 deletion source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ NexT.utils = {

const imageTitle = $image.attr('title') || $image.attr('alt');
if (imageTitle) {
$imageWrapLink.append(`<p class="image-caption">${imageTitle}</p>`);
// Do not append image-caption if pandoc has already created a figcaption
if (!$imageWrapLink.next('figcaption').length) {
$imageWrapLink.append(`<p class="image-caption">${imageTitle}</p>`);
}
// Make sure img title tag will show correctly in fancybox
$imageWrapLink.attr('title', imageTitle).attr('data-caption', imageTitle);
}
Expand Down

0 comments on commit c377515

Please sign in to comment.