Skip to content

Commit a033b35

Browse files
figcaption: Adds figcaption
Wraps images with longdesc attribute in a figure elements and adds a figcaption element with the longdesc text.
1 parent 309d86e commit a033b35

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,22 @@ function wikify_link($node) {
601601
$node->text('');
602602
}
603603

604+
function add_captions_to_all_images($element) {
605+
foreach ($element->findXPath(".//img[@longdesc]") as $img) {
606+
add_caption_to_image($img);
607+
}
608+
}
609+
610+
function add_caption_to_image($img) {
611+
$figure = new DOMWrap\Element('figure');
612+
$img->parentNode->insertBefore($figure, $img);
613+
$figure->append($img);
614+
$text = $img->getAttribute('longdesc');
615+
/** @var DOMWrap\Element $html */
616+
$caption = new DOMWrap\Element('figcaption', $text);
617+
$figure->append($caption);
618+
}
619+
604620
/*
605621
Function: versionSelector
606622
generate html select element with available revisions for given page

0 commit comments

Comments
 (0)