Skip to content

Instantly share code, notes, and snippets.

@letunglam
Forked from bastianallgeier/figure.php
Created August 5, 2013 21:04
Show Gist options
  • Save letunglam/6159614 to your computer and use it in GitHub Desktop.
Save letunglam/6159614 to your computer and use it in GitHub Desktop.
<?php
class kirbytextExtended extends kirbytext {
function __construct($text=false, $markdown=true, $smartypants=true) {
parent::__construct($text, $markdown, $smartypants);
// define custom tags
$this->addTags('figure');
// define custom attributes
$this->addAttributes('caption');
}
// 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
$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