Skip to content

Instantly share code, notes, and snippets.

@sjelfull
Forked from simonscheiber/figure.php
Last active August 29, 2015 14:10
Show Gist options
  • Save sjelfull/202ef25a81cfb6c65f17 to your computer and use it in GitHub Desktop.
Save sjelfull/202ef25a81cfb6c65f17 to your computer and use it in GitHub Desktop.
<?php
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
// define custom tags
$this->addTags('figure');
// define custom attributes
$this->addAttributes('caption', 'class');
}
// define a function for each new tag you specify
function figure($params) {
// we need to change this to make the image function work.
$params['image'] = $params['figure'];
// try to fetch the caption from the alt text if not specified
if(empty($params['caption'])) $params['caption'] = @$params['alt'];
// try to fetch the alt text from the caption if not specified
if(empty($params['alt'])) $params['alt'] = @$params['caption'];
// start the html output with or without a class
if(!empty($params['class'])) {
$html = '<figure class="' . $params['class'] . '">';
} else {
$html = '<figure>';
}
$html .= $this->image($params);
// only add a caption if one is available
if(!empty($params['caption'])) {
$html .= '<figcaption>' . $params['caption'] . '</figcaption>';
}
$html .= '</figure>';
return $html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment