Skip to content

Commit c98967a

Browse files
figcaption: Adds figcaption
Wraps images with title or data-attribution attribute in a figure element. Places the title in a figcaption element. Places the data-attribution in a small element.
1 parent e00160a commit c98967a

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
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;

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
if ($hyphaPage) processCommandResult($hyphaPage->process($O_O->getRequest()));
126126

127127
registerPostProcessingFunction('dewikify');
128+
registerPostProcessingFunction('add_captions_to_all_images');
128129

129130
// add hypha commands and navigation
130131
$_cmds[] = '<a class="index" href="index/'.$hyphaLanguage.'">'.__('index').'</a>';

system/core/pages.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,39 @@ function wikify_link($node) {
601601
$node->text('');
602602
}
603603

604+
function add_captions_to_all_images($element) {
605+
/** @var \DOMWrap\NodeList $img */
606+
// process images that reside within "main"
607+
foreach ($element->findXPath('//*[@id="main"]//img[@title or @data-attribution]') as $img) {
608+
// do not process images that reside within the wymeditor
609+
if ($img->parents('.wymeditor')->count() === 0) {
610+
add_caption_to_image($img);
611+
}
612+
}
613+
}
614+
615+
function add_caption_to_image($img) {
616+
$doc = $img->document();
617+
618+
$img->wrap('<figure>');
619+
$caption = $doc->createElement('figcaption');
620+
$img->after($caption);
621+
622+
$title = $img->getAttribute('title');
623+
if ($title) {
624+
$span = $doc->createElement('span', $title);
625+
$span->addClass('title');
626+
$caption->append($span);
627+
}
628+
629+
$attribution = $img->getAttribute('data-attribution');
630+
if ($attribution) {
631+
$small = $doc->createElement('small', $attribution);
632+
$small->addClass('attribution');
633+
$caption->append($small);
634+
}
635+
}
636+
604637
/*
605638
Function: versionSelector
606639
generate html select element with available revisions for given page

0 commit comments

Comments
 (0)