Skip to content

Commit 2f15bc0

Browse files
fixup! figcaption: Adds figcaption
1 parent a26df84 commit 2f15bc0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

data/themes/default/hypha.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ img {
525525
height: auto;
526526
}
527527

528+
#main figure .title + .attribution:before {
529+
content: " - ";
530+
}
531+
528532
#main img.left {
529533
float: left;
530534
margin: 0 13px 10px 0;

system/core/pages.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ function wikify_link($node) {
604604
function add_captions_to_all_images($element) {
605605
/** @var \DOMWrap\NodeList $img */
606606
// process images that reside within "main"
607-
foreach ($element->findXPath('//*[@id="main"]//img[@title] | //*[@id="main"]//img[@data-attribution]') as $img) {
607+
foreach ($element->findXPath('//*[@id="main"]//img[@title or @data-attribution]') as $img) {
608608
// do not process images that reside within the wymeditor
609609
if ($img->parents('.wymeditor')->count() === 0) {
610610
add_caption_to_image($img);
@@ -613,19 +613,24 @@ function add_captions_to_all_images($element) {
613613
}
614614

615615
function add_caption_to_image($img) {
616-
$figure = new DOMWrap\Element('figure');
617-
$img->parentNode->insertBefore($figure, $img);
618-
$figure->append($img);
616+
$doc = $img->document();
617+
618+
$img->wrap('<figure>');
619+
$caption = $doc->createElement('figcaption');
620+
$img->after($caption);
619621

620622
$title = $img->getAttribute('title');
621-
$text = $title ? $title : '';
622-
$caption = new DOMWrap\Element('figcaption', $text);
623-
$figure->append($caption);
623+
if ($title) {
624+
$span = $doc->createElement('span', $title);
625+
$span->addClass('title');
626+
$caption->append($span);
627+
}
624628

625629
$attribution = $img->getAttribute('data-attribution');
626630
if ($attribution) {
627-
$small = new DOMWrap\Element('small', $attribution);
628-
$figure->append($small);
631+
$small = $doc->createElement('small', $attribution);
632+
$small->addClass('attribution');
633+
$caption->append($small);
629634
}
630635
}
631636

0 commit comments

Comments
 (0)