File tree 2 files changed +29
-0
lines changed 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 125
125
if ($ hyphaPage ) processCommandResult ($ hyphaPage ->process ($ O_O ->getRequest ()));
126
126
127
127
registerPostProcessingFunction ('dewikify ' );
128
+ registerPostProcessingFunction ('add_captions_to_all_images ' );
128
129
129
130
// add hypha commands and navigation
130
131
$ _cmds [] = '<a class="index" href="index/ ' .$ hyphaLanguage .'"> ' .__ ('index ' ).'</a> ' ;
Original file line number Diff line number Diff line change @@ -601,6 +601,34 @@ function wikify_link($node) {
601
601
$ node ->text ('' );
602
602
}
603
603
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] | //*[@id="main"]//img[@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
+ $ figure = new DOMWrap \Element ('figure ' );
617
+ $ img ->parentNode ->insertBefore ($ figure , $ img );
618
+ $ figure ->append ($ img );
619
+
620
+ $ title = $ img ->getAttribute ('title ' );
621
+ $ text = $ title ? $ title : '' ;
622
+ $ caption = new DOMWrap \Element ('figcaption ' , $ text );
623
+ $ figure ->append ($ caption );
624
+
625
+ $ attribution = $ img ->getAttribute ('data-attribution ' );
626
+ if ($ attribution ) {
627
+ $ small = new DOMWrap \Element ('small ' , $ attribution );
628
+ $ figure ->append ($ small );
629
+ }
630
+ }
631
+
604
632
/*
605
633
Function: versionSelector
606
634
generate html select element with available revisions for given page
You can’t perform that action at this time.
0 commit comments